Hi.
I have the following string "aaaaaa££aaaaa£aaaaa££"
and i want to replace £ for € and ££ for £.
(the string may change, but the rules are the same)
i've tried doing the following :
stringvar.replace(/[£]/g,"\u20AC")).replace(/[££]/g,"£")
It's obvious that the first replace replaces all £ by €..so the second replace never happens.
I'm trying to find a regular expression that helps me on this case, like saying to the replace that if he find a £ isolated from other £ he can replace for €. If not replace with £.
Hope you can help.
Cheers.
I have the following string "aaaaaa££aaaaa£aaaaa££"
and i want to replace £ for € and ££ for £.
(the string may change, but the rules are the same)
i've tried doing the following :
stringvar.replace(/[£]/g,"\u20AC")).replace(/[££]/g,"£")
It's obvious that the first replace replaces all £ by €..so the second replace never happens.
I'm trying to find a regular expression that helps me on this case, like saying to the replace that if he find a £ isolated from other £ he can replace for €. If not replace with £.
Hope you can help.
Cheers.
Edgar SantosPosted Apr 11, 2008, 7:21 PM
Ok, thank you. Problem solved.
Cheers.
AlanPosted Apr 10, 2008, 7:42 PM
The trick here is to replace "££" not with "£" but with something that your string will never contain such as a null character. You can then replace "£" with the euro symbol and, finally, replace the null character with a "£".
I don't know what the code is in Javascript but in C# it's:
string stringvar = "aaaaaa££aaaaa£aaaaa££";
string euro = "\u20AC";
stringvar = Regex.Replace(stringvar,"££","\0");
stringvar = Regex.Replace(stringvar,"£",euro);
stringvar = Regex.Replace(stringvar,"\0","£");
MessageBox.Show(stringvar);
Bechir BejaouiPosted Apr 10, 2008, 7:12 AM
Of Corse add using System.Threading;
to your project then
Add this line of code to your current thread
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-UK");
you can change the "en-UK" to many other cultures to suite your needs
Ohter solution is to use the Expresso 3.0 software witch is a regular expressions builder