I need to transliterate a Hebrew text. So wrote a little Python script, which reads-in the Hebrew text from a text file, globally replaces the Hebrew letters with Latin ones. Now I need to do some fine tuning (replace certain things in some position but not in other, so a global replace won't do). The trouble is the following: The read-in text is a string so I cannot replace individual string elements. So, what would be the best way to do it?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Convert your string into a list. Either a list of letters or (if this works in your case) a list of words. This is a basic approach but should work if your string is stored in writing order (rather than display order).
If you are needing to pull the ";" out of "Hebrew W;rd" rather than writing a list and iterating through it, just find the replacing character and replace it.
If the conversion from Hebrew to Latin leaves ";" where "x" should be, loop through and replace the characters.
If some ";" are legit within the string, than just require conditions before executing the code to narrow down what bad characters to replace.
The real trick is not whether to use lists or strings, but writing the conditions well enough that parsing the code will be accurate.