Add quotation at the start and end of each line
Jump to navigation
Jump to search
將每行的文字,都加上引號框起來,並且移除換行
// before Elmo Emie Granny Bird // after 'Elmo', 'Emie', 'Granny Bird'
Add quotation at the start and end of each line[edit]
Using Notepad++[1] or sublime text
- Find what: (.*)
- Replace with: '\1',
(如果要使用雙引號框起來,則是 Replace with: "\1")
Using python
import re input = "a\nbb \nccc\n \ndddd\n" print(input) pattern = r"(.*)\n" replace = r'"\1"\n' print("#### result ####\n") print(re.sub(pattern, replace, input))
Add quotation at the start and end of each line, remove return symbol & add comma symbol[edit]
Data condition 1: Trim whitespace of each line[edit]
方法1: 使用 Sublime Text 、Notepad++ 或 EmEditor。該方法有處理每行的前面或後面可能有一格或多格空白
如果使用 Mac 作業系統
- Find what: (\S+)(\s?)+$\n
- Replace with: '\1',
(如果要使用雙引號框起來,則是 Replace with: "\1", )
如果使用 Win 作業系統,需要修改換行符號 \n 為 \r\n
- Find what: (\S+)(\s?)+$\r\n on Mac
- Replace with: '\1',
(如果要使用雙引號框起來,則是 Replace with: "\1", )
Data condition 2: Not trim whitespace of each line[edit]
方法2: 使用 Sublime Text 或 EmEditor 該方法沒有處理每行的後面可能有一格或多格空白
- Find what: (.*)$\n 或 (\S+)$\n 或 (\S+)\n
- Replace with: '\1',