You need to sign in to do that
Don't have an account?
Developer_shaan
Insertion of comma after evry third character in a string
I have a string which has value as "24098909090" .Now i need to display the value in thousands.
i.e after every third charcter in a string a comma should be inserted.
Ex: "24,098,909,090" .
Is there any solution for this....
How to make use of Javascript or Apex script to handle this kind of issue??
Thanks
shaan
In regular expressions, look at grouping and lookahead.
string num = '123456789';
string regex = '(\\d)(?=(\\d{3})+$)';
system.assertEquals('123,456,789', num.replaceAll(regex, '$1,'));
Best, Steve.
All Answers
In regular expressions, look at grouping and lookahead.
string num = '123456789';
string regex = '(\\d)(?=(\\d{3})+$)';
system.assertEquals('123,456,789', num.replaceAll(regex, '$1,'));
Best, Steve.
Excellent Steve.
Thats was the best soln.Instead i was wasting my time on javascript.
Thats was so simple to use.
Can you please let me know how to write this expressions or else any docs related on this regular expressions.
Depending on where/how you want to do this, you may also be able to just get this kind of formatting done automatically by VF using outputText's formatting capabilities. See
http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_compref_outputText.htm
As an aside, I actually agree with the poster who says that you should use currency fields if you're manipulating currency. However that wasn't what you asked, so I didn't go there.
I'm not sure what you're asking about how to write the expression? There are a zillion, literally one zillion, or perhaps a bazillion, articles, blogs, tutorials, etc. about how to use Regular Expressions. I don't have one offhand that I can point you do, just google them and you'll find more than you want. There's entire books as well.
Best, Steve.