?
Solved

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

Posted on 2008-10-18
3
Medium Priority
?
500 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 2000 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

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

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 …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

800 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