Editing
Add quotation at the start and end of each line
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
將每行的文字,都加上引號框起來,並且移除換行 <pre> // before Elmo Emie Granny Bird // after 'Elmo', 'Emie', 'Granny Bird' </pre> == Add quotation at the start and end of each line == Using Notepad++<ref>[https://stackoverflow.com/questions/8849357/add-quotation-at-the-start-and-end-of-each-line-in-notepad regex - Add quotation at the start and end of each line in Notepad++ - Stack Overflow]</ref> or sublime text * Find what: {{kbd | key = <nowiki>(.*)</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 == === Data condition 1: Trim whitespace of each line === 方法1: 使用 [http://www.sublimetext.com/ Sublime Text] 、[https://notepad-plus-plus.org/downloads/ Notepad++] 或 [https://zh-tw.emeditor.com/ EmEditor]。該方法有處理每行的前面或後面可能有一格或多格空白 如果使用 {{Mac}} 作業系統 * Find what: {{kbd | key = <nowiki>(\S+)(\s?)+$\n</nowiki>}} * Replace with: {{kbd | key = <nowiki>'\1', </nowiki>}} <br />(如果要使用雙引號框起來,則是 Replace with: {{kbd | key = <nowiki>"\1", </nowiki>}}) 如果使用 {{Win}} 作業系統,需要修改換行符號 {{kbd | key = <nowiki>\n</nowiki>}} 為 {{kbd | key = <nowiki>\r\n</nowiki>}} * Find what: {{kbd | key = <nowiki>(\S+)(\s?)+$\r\n</nowiki>}} on {{Mac}} * Replace with: {{kbd | key = <nowiki>'\1', </nowiki>}} <br />(如果要使用雙引號框起來,則是 Replace with: {{kbd | key = <nowiki>"\1", </nowiki>}}) === Data condition 2: Not trim whitespace of each line === 方法2: 使用 [http://www.sublimetext.com/ Sublime Text] 或 EmEditor {{exclaim}} 該方法沒有處理每行的後面可能有一格或多格空白 * Find what: {{kbd | key = <nowiki>(.*)$\n</nowiki>}} 或 {{kbd | key = <nowiki>(\S+)$\n</nowiki>}} 或 {{kbd | key = <nowiki>(\S+)\n</nowiki>}} * Replace with: {{kbd | key = <nowiki>'\1', </nowiki>}} == References == <references /> [[Category:Regular expression]] [[Category:Software]] [[Category:Programming]] [[Category:Data Science]] [[Category:String manipulation]]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Exclaim
(
edit
)
Template:Kbd
(
edit
)
Template:Mac
(
edit
)
Template:Win
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information