sshika 3 Posted July 11, 2015 Share Posted July 11, 2015 Hello Is itpossible to edit a file .txt and replace characters by other characters ? thank you Quote Link to post Share on other sites
0 kevinkk525 8 Posted July 11, 2015 Share Posted July 11, 2015 It is, just load the file into a variable (e.g. text="abcdefabcdef") and run the following command: newtext=text:gsub(char,newchar) so e.g. newtext=text:gsub("a","c") will give newtext="cbcdefcbcdef". now just save that string to your file (overwrite the file) Quote Link to post Share on other sites
0 sshika 3 Posted July 11, 2015 Author Share Posted July 11, 2015 Ok What is the characters for "enter" ? Quote Link to post Share on other sites
0 kevinkk525 8 Posted July 11, 2015 Share Posted July 11, 2015 for a new line? \n Quote Link to post Share on other sites
0 sshika 3 Posted July 11, 2015 Author Share Posted July 11, 2015 Ok If i use this it's ok ? text="abcdefabcdef" newtext=text:gsub(char,newchar newtext=text:gsub("fa",/n) And the result is this ? newtext="cbcde"/n"bcdef" Quote Link to post Share on other sites
0 kevinkk525 8 Posted July 11, 2015 Share Posted July 11, 2015 yes that does work this way. Quote Link to post Share on other sites
0 dgelessus 26 Posted July 11, 2015 Share Posted July 11, 2015 Not quite. Backslash escapes (like \n for newline) need to be inside the string, like "first line\nsecond line". It is important that you use a backslash (\), not a forward slash (/). Wikipedia tells me that on AZERTY keyboards the backslash is on AltGr + 8. Quote Link to post Share on other sites
0 kevinkk525 8 Posted July 12, 2015 Share Posted July 12, 2015 thanks for clarification, i did not read his answer carefully enough. the result is of course newtext="cbcde\nbcdef" if you use the backslash. Quote Link to post Share on other sites
Hello
Is itpossible to edit a file .txt and replace characters by other characters ?
thank you
Link to post
Share on other sites