c# - Using Regular Expressions for Pattern Finding with Replace -


i have string in following format in comma delimited file:

sometext, "text with, delimiter", moretext, "text again" 

what need create method through string, , replace commas inside of quoted text dollar sign ($).

after method, string be:

sometext, "text with$ delimiter", moretext, "text again" 

i'm not entirely regex, know how can use regular expressions search pattern (finding comma in between quotes), , replace comma dollar sign.

personally, i'd avoid regexes here - assuming there aren't nested quote marks, quite simple write for-loop, think more efficient:

var inquotes = false; var sb = new stringbuilder(sometext.length);  (var = 0; < sometext.length; ++i) {     if (sometext[i] == '"')     {         inquotes = !inquotes;     }      if (inquotes && sometext[i] == ',')     {         sb.append('$');     }     else     {         sb.append(sometext[i]);     } } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -