Regex for thousands separator?
Hi,
I am need to scrape sites with foreign currencies which are in the thousands range ($1,000). The data are then transferred to MySQL database. MySQL has problems with commas (,) and read it as a decimal point. So something that is "100,000" ends up being "100". I am not really familiar with Mysql, so I was wondering is there a way to use Regular Expressions that can scape "$54,321" into "54321"?
Any suggestion is greatly appreciated! Thank you in advance!
Test_Scraper, In a script
Test_Scraper,
In a script that is called after you extract the data you can do something like the following to remove the comma.
//Set the value of your session variable to a local variable.
myVar = session.getVariable("myVar");
//Replace all instances of a comma with an empty string.
myVar = myVar.replaceAll(",","");
//Set the value of your local variable (now without a comma)
// to the value of your session variable.
session.setVariable("myVar",myVar);
Or do the same thing in one line of code.
session.setVariable("myVar", session.getVariable("myVar").replaceAll(",",""));
Hope this helps.
-Scott
I have a function I use over
I have a function I use over and over to parse a scraped string to an Integer:
makeNum(num)
{
if (num!=null)
{
num = String.valueOf(num);
num = num.replaceAll("\\D", "");
if (num.length()>0)
{
num = Integer.parseInt(num);
}
else
num = 0;
}
else
num = 0;
return num;
}