Solved

how to remove unwanted characters from a string and convert it to an integer value using CFML

Posted on 2008-10-18
3
490 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:xoundboy
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
azadisaryev earned 500 total points
ID: 22747820
<cfset mystring = "EUR 123,456,789">
<cfset myInt = replace(listlast(mystring, " "), ",", "", "All")>
0
 
LVL 2

Author Comment

by:xoundboy
ID: 22747871
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!

0
 
LVL 2

Author Comment

by:xoundboy
ID: 22747905
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
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now