Add quotation at the start and end of each line: Difference between revisions
Jump to navigation
Jump to search
(Created page with "將每行的文字,都加上引號框起來,並且移除換行 <pre> // before Elmo Emie Granny Bird // after 'Elmo', 'Emie', 'Granny Bird' </pre> == Add quotation at t...") |
|||
Line 15: | Line 15: | ||
* Find what: {{kbd | key = <nowiki>(.*)</nowiki>}} | * Find what: {{kbd | key = <nowiki>(.*)</nowiki>}} | ||
* Replace with: {{kbd | key = <nowiki>'\1', </nowiki>}} <br />(如果要使用雙引號框起來,則是 Replace with: {{kbd | key = <nowiki>"\1"</nowiki>}}) | * Replace with: {{kbd | key = <nowiki>'\1', </nowiki>}} <br />(如果要使用雙引號框起來,則是 Replace with: {{kbd | key = <nowiki>"\1"</nowiki>}}) | ||
Using python | |||
<pre> | |||
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)) | |||
</pre> | |||
== Add quotation at the start and end of each line, remove return symbol & add comma symbol == | == Add quotation at the start and end of each line, remove return symbol & add comma symbol == |
Latest revision as of 14:55, 20 February 2022
將每行的文字,都加上引號框起來,並且移除換行
// 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',