Remove Double Quotes from numbers only

I want to remove all double quotes with regex in a CSV file if this happens between double quotes. I am currently using the following regex for this: only from numbers, not from alphabets. Input signal

"000027679","ROMANO","CRYSTAL","S","FT","19990706","19990706","A",,"006901",

I tried this regex expression

string newcontent = Regex.Replace(contents, @"[\""]", "");

but this is the removal of all double quotes that I don't want. I want to remove only double quotes from numbers.

+4
source share
2 answers

You can do this with the captured group in regex, use regex and replace it with the captured value "(\d+)"


CODE:
string contents="\"000027679\",\"ROMANO\",\"CRYSTAL\",\"S\",\"FT\",\"19990706\",\"19990706\",\"A\",,\"006901\"";
string newcontent = Regex.Replace(contents,@"""(\d+)""", "$1");<hr>

OUTPUT:

000027679,"ROMANO","CRYSTAL","S","FT",19990706,19990706,"A",,006901
+3
source

. , , .

string newcontent = Regex.Replace(contents, @"(?<=\d+\d)[""]|[""](?=\d+\d)", "");
0

Source: https://habr.com/ru/post/1615862/


All Articles