Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting text with commas to numeric
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00328921
Message ID:
00328946
Views:
15
>Hi,
>
>In my application, I have a text file that I have to slice, dice and reformat. I have created the table to import the text file into and have created the required fields.
>
>Here's my problem - I'm not sure how to convert the text dollar amounts (i.e. 22,000,000.00) into a text dollar amount (i.e. 22000000.00) so that I can use the val function to convert it to a numeric value. Is there an relatively simple way to do this? The text file has about 10,000 records.
>

How about using CHRTRAN() to remove the commas?

? CHRTRAN('22,000,000.00',',','') && prints 22000000.00

If you need to be a bit more selective,and not remove all commas, just the ones preceded and followed immediately by a digit, try the Vbscript.RegExp object from the WSH:
oRegExp = CREATEOBJ('Vbscript.RegExp')
oRegExp.pattern = "(\d{1}),(\d{1})"
? oRegExp.Replace('This, string has 1,000 different, things with 1 ,1 commas',"$1$2")
Regular expressions RULE!
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform