xoundboy
asked on
how to remove unwanted characters from a string and convert it to an integer value using CFML
I have a string variable that contains costs in the form 'EUR 123,456,789'
I need to convert it into an integer so that it can be inserted into an INT type mysql field. in other words I need it to be in the form '123456789' without the 'EUR' or the commas separating thousands.
How can I do this in CFML?
thanks
I need to convert it into an integer so that it can be inserted into an INT type mysql field. in other words I need it to be in the form '123456789' without the 'EUR' or the commas separating thousands.
How can I do this in CFML?
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found a solution that works in my case using regex (it's actually really easy!)
<cfset myInt = rereplace(myString,"\D","" ,"all")>
the regex \D corresponds to any character other than a number ---perfect
<cfset myInt = rereplace(myString,"\D",""
the regex \D corresponds to any character other than a number ---perfect
ASKER
I would prefer a method that instead of replacing specific characters with "" would just strip away any characters that are not digits. I imagine it will require a regex of some type but I'm rubbish at regex!