Page 1 of 1
How to remove comma in the string of Amount of 2,050
Posted: Sun Jan 21, 2007 1:49 pm
by amir
Hello,
I am getting input from the user through a CSV file and the format of that string is
Code: Select all
15/11/2006,Hello,Yes,2.1,1,"2,050",45,94.5,0,0,0
. . .
. . .
. . .
and so on.
I want to remove comma from each entry of "2,050". It should be "2050".
TIA.
Posted: Sun Jan 21, 2007 2:16 pm
by John Cartwright
Code: Select all
$source = '15/11/2006,Hello,Yes,2.1,1,"2,050",45,94.5,0,0,0';
echo preg_replace('#"(\d+),(\d+)"#', '$1$2', $source);
Not tested, but should be ok. Enjoy.
Moved to Regex.
Posted: Sun Jan 21, 2007 2:21 pm
by amir
Thanks a lot!
Posted: Sun Jan 21, 2007 2:23 pm
by superdezign
Be aware that the code shown will remove the quotation marks unless you use '"$1$2"' instead. Just in case you wanted to keep them.
Posted: Tue Jan 23, 2007 1:01 am
by joboy
what about the opposite scenario, in my case i need to retain the commas. let's say the value in a field(of a table) contains similar to this:
"apple, banna, and mango. " (pls. exlude the double quotes).
how will i put this single value to a single cell in excel?..what i have right now is every "fruit" were separately placed in three adjacet cells, obviously because they are comma separated values (CSV).
thanks.
Posted: Tue Jan 23, 2007 1:53 am
by joboy
never mind guys, if a variable or field's content contains comma(s)..what's needed is just to enclosed it with double quotes.