Solved

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

Posted on 2008-10-18
3
498 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coldfusion update database with CFLOOP 5 69
CSS HELP 6 102
Run ColdFusion website locally 1 42
ColdFusion not showing binary json data in request 4 85
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

737 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