问题
I have a dialogue script for a game that needs to be formatted in XML, with following format...
<line id='1'> .............. </line>
<line id='2'> .............. </line>
<line id='3'> .............. </line>
....
<line id='n'> .............. </line>
Dialogue script I've given right now is written in plain format, I only need to wrap each lines in XML tags above.
Is there a way to automate the process?
回答1:
You can achieve this in two steps. First, add a line number to the start of each line of your text file. Then, wrap each line in the <line>
XML tags which you need.
To generate line numbers, you can use column editor mode. First, insert a space the start of each line via this find and replacement:
Find:
(.*)
Replace:
$1 (single space followed by $1)
Then use column editor mode to insert a generated line number at the start of each line. See here for more information on how to do this. At this point, your data should look something like this:
1 Here is line one.
2 Here is line two.
3 Here is line three.
...
111 Here is line one hundred eleven.
Now you can do a second find and replacement to wrap each line in the <line>
tag:
Find:
([0-9]+)\s+(.*)
Replace:
<line id='$1'>$2</line>
来源:https://stackoverflow.com/questions/46761958/automatically-wrap-custom-xml-tags-and-numbering-them