Click to See Complete Forum and Search --> : currency formatting and string manipulation


aapun
04-03-2003, 11:06 AM
I want to display localized prices (using javascript). Currency format is different for different countries. Luckily I want to display currencies, only in France, Germany, UK and US.

Any inputs on how do i take care of formatting my price depending on a locale? Had it been java, it was much simpler.

String Manipulation: ?
I need to break a string in a particular pattern, and store the broken pieces into an array:
(two chars), (two chars), ... . . . . (three chars), (two chars)

Please suggest the simplest way to do this. While loop and a sequence of "if" statements is the obvious solution. Can any one make use of "split" or "regular expression" some how and solve it ?

example1:
1293878334
output:
(1)(29)(38)(783)(34)

example2:
12334
output:
(123)(34)

example3:
334
output:
(3)(34)

Thanks in advance.
~aapun

Vladdy
04-03-2003, 11:14 AM
Regular Expressions is the answer.

aapun
04-03-2003, 02:54 PM
Vladdy ,
I know it can be done using reg ex. My question was, how ? I am preety sure that if reg ex is the solution, the code cannot be more then 3 to 4 lines.

In case you know the solution, can you please share it ?

Thank you
aapun

Vladdy
04-03-2003, 04:05 PM
The actual reg exp will depend on your exact needs. Read this (http://devedge.netscape.com/library/manuals/2000/javascript/1.5/guide/regexp.html#1010922), it has all the information you need.