One sample is used to replace double quote from words which encapsulated by Csvwriter,
You know CSV writer would take care of the double quote and comma and new line,
So if the words have comma or new line, CSV writer would use the default text qualifier double quote
Enclose them, sample:
Source:evan,yao CSV: "Evan,yao"
And it'll replace every double quote with double quote.
Such as source data is Evan,yao "CSV:" Evan,yao "" "
So when we read CSV words, we should replace the additional double quote,
I use C # and Regex to does this, the following are the simple sample.
One is the Remove text qualifier, another one is replace demo.
Please enjoy.
usingSystem;usingSystem.Text.RegularExpressions;usingSystem.IO;usingSystem.Collections; Public classtest{ Public Static stringRemovetextqualifier (stringtext) {stringPattern ="^\ "(? <word>.*) \" $"; Regex RGX=NewRegex (pattern); MatchCollection matches=RGX. Matches (text);if(matches. Count>0)returnmatches[0]. groups[0]. Value.replace ("\"\"","\"");Elsereturntext;} Public Static voidRegexreplacedemo (inttype) {stringWords ="Letter Alphabetical missing lack release"+"penchant slack acryllic laundry cease";if(Type = =2) Words=@"Select *from table1 left join table2 on table1.col1=table2.col2right join T3 on Table1.col2=t3.col1 full join T4 on t 4.c1=t3.col2 where 1=1and 2=2 or 3=3"; Console.WriteLine ("Original Words:"); Console.WriteLine (words); Console.WriteLine (); Console.WriteLine ("First Letter Capital words:"); Console.WriteLine (Regex.Replace (words,@"\w+", (m) = = {//Change the first letter to capitalizeif(Type = =1)returnm.value[0]. ToString (). ToUpper () + m.value.substring (1);Else{stringKeywordslist ="select from where and or joins left right";if(Keywordslist. IndexOf (" "+ M.value +" ") >-1)returnM.value.toupper ();ElsereturnM.value;}));} Public Static voidMain (string[] args) {Regexreplacedemo (1); Regexreplacedemo (2);} }
dotnet Use regex-samples