Link to home
Start Free TrialLog in
Avatar of xoundboy
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
ASKER CERTIFIED SOLUTION
Avatar of azadisaryev
azadisaryev
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xoundboy
xoundboy

ASKER

Unfortunately that doesn't work. It would normally I'm sure, but the problem is that the string variable has been iported into mysql table from an xls spreadsheet and some wierd stuff has happened - I don't know what, but in the string, although it looks like a normal space between the 'EUR' and the first set of digits it obviously isn't.

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!

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