Effect of local PC settings on parsing text
An interesting little problem arose recently in the context of a script that is required to run in several locations around the world. Solving the immediate problem is straightforward enough, but I wondered whether there's a more general solution.
The problem was caused by some of the PCs on which the script was being run having different settings for their number formats. In this instance the decimal point in one location had been set to "·" (ASCII code 250) as opposed to the usual one on a UK keyboard ("."). In Windows 7 this can be changed in Control Panel | Clock Language and Region | Change the Date, Time or Number Format | Additional Settings | Decimal Symbol.
The effect was that any line involving an eval(parse(...)) construction crashed the program, as this trivial example shows:
A = 123.456; B = 1.0;
TextToParse = "C = " || char(A+B);
eval(parse(TextToParse));
Unexpected "·456". Perhaps there is a missing ";" or ",".
Line 1 Column 8: C = 124►·456
The remaining text that was ignored was
·456
124
To sort this out obviously all I need to do is write a small function of my own to replace the "char" function, looking for any unexpected characters in a text field which I know should be a number, and replacing them with the normal decimal point. However, I'd like to know if there's a universal fixit to interpret correctly something more complicated like a user with Arabic or Cyrillic numerals, or negative numbers being displayed in parenthesis. Does anybody know if there is?
(Incidentally, I've tried changing other settings within the "Additional Settings" screen without encountering any difficulties: the decimal point is the only one I've found that causes trouble so far, but I imagine there could potentially be others.)