*SOLVED* Is it ideal to use .replace() over 40 times on a string?
in
Programming Questions
•
1 month ago
Hi there :)
Quick question really... I am creating a 'Learn French' program in processing, and I allow the user to create 'Question Sheets' in a txt file. For some reason processing cannot read any accented letter (at least from a txt file), and when it should be displayed a rectangle symbol replaces it.
I have decided to get the user to use <u for ú and ^i for î etc.
I have implemented this by reading each line of the txt file, and check in that line for those combinations I have shown above, and do any necessary replacements. Now, as you can see below I use a lot of .replace() functions, is this alright? (in terms of lag and memory) Or is there a better way? (also I only update the modified finished string once when the program loads, so this isn't running all the time):
- string.replace("<u", "ú").replace(">u", "ù").replace("<U", "Ú").replace(">U", "Ù").replace("^u", "û").replace("^U", "Û").replace(">E", "È").replace("<E", "É").replace("^e", "ê").replace("^E", "Ê").replace(">a", "à").replace("<a", "á").replace("^a", "â") //etc. etc.
This post is probably far too complicated for what it's worth, but I have to go very soon and it would be best if I submitted it beforehand, so apologies in advance.
KingD.
1