Re: How to remove quotes, commas, from numbers (considered as strings)?




sherifffruitfly wrote:

Example csv line:

43.56,345.2,"1,285,100",45.6

I would like to replace the quoted-comma'd numbers with their
unquoted-uncomma'd versions. I'm reading the csv line-by-line, putting

Another way to achieve the goal is using of MatchEvaluator.

ASP.Net 2.0
string pattern = "\"([0-9.,]+)\"";
string testStr = "43.56,345.2,\"1,285,100\",45.6";
MatchEvaluator eval = delegate (Match match)
{
return match.Groups[1].Value.Replace(",","");
};
testStr = new Regex(pattern).Replace(testStr, eval);


ASP.Net 1.1
void foo()
{
string pattern = "\"([0-9.,]+)\"";
string testStr = "43.56,345.2,\"1,285,100\",45.6";
testStr = new Regex(pattern).Replace(testStr, new
MatchEvaluator(eval));
}

static string eval(Match match)
{
return match.Groups[1].Value.Replace(",", "");
}

.



Relevant Pages

  • Re: non-robust way of reading a "csv" file
    ... directed input, I decided to try this method of reading a CSV file ... integer ierr ... Well that seems to me like a rather nice and simple way of reading CSV. ...
    (comp.lang.fortran)
  • Checking File Attributes of Excel CSV over Inter/Intra Net
    ... I have been reading up on DSO for closes files, ... BuiltinDocumentProperties but none seem to work over the web. ... I have to check a CSV every morning at random times to see if its ...
    (microsoft.public.excel.programming)
  • CSV reading
    ... Just a small query as to the most efficient method of reading a .csv ... file that contains both qualitative and quantitative information. ... csvread function is limited to numeric elements only, ...
    (comp.soft-sys.matlab)
  • Re: Cant seem to use FileSystemObject
    ... I can't confirm that the file is a genuine csv. ... Is there any instance of the editor ... TransferText doesn't put the data in a table? ... OpenTextFile is an alternate way of reading a file, ...
    (comp.databases.ms-access)
  • Re: Organize and Print CSV data
    ... which can be done even direct in the reading part. ... ADO is the way to go when accessing CSV files. ... AcctNo, Name, junk, junk, Address, junk, PhoneNo ... stock (30 labels per sheet, 3 columns, 10 rows). ...
    (microsoft.public.dotnet.languages.vb)