Solved

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

Posted on 2008-10-18
3
499 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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