replacing text within quotes until next quote

Posted by Jordan Trainor on Stack Overflow See other posts from Stack Overflow or by Jordan Trainor
Published on 2012-12-16T17:01:43Z Indexed on 2012/12/16 17:03 UTC
Read the original article Hit count: 231

Filed under:
|
|
|
String input = "helloj\"iojgeio\r\ngsk\\"jopri\"gj\r\negjoijisgoe\"joijsofeij\"\"\"ojgsoij\"";

This is my current code that works but iv added some code that has to run before this which makes some '"' split onto another line thus making the code below obsolute unless under certain cirumstances the '"' is not put onto the next line.

firstQuote = input.IndexOf("\"");
lastQuote = input.LastIndexOf("\"");
input = input.Substring(0, firstQuote) + "<span>quote" +
    input.Substring(firstQuote + 1, lastQuote - (firstQuote + 1) + "quote</span>" +
    input.Substring(lastQuote + 1, lines.Length - (lastQuote + 1);

How could I change the input string from

input = "helloj\"iojgeio\r\ngsk\\"jopri\"gj\r\negjoijisgoe\"joijsofeij\"\"\"ojgsoij\"";

to

input = "helloj(<span>quoteiojgeio\r\ngsk\\"jopriquote</span>gj\r\negjoijisgoe<span>quotejoijsofeijquote</span>quote<span>quote</span>ojgsoij<span>quote</span>";

© Stack Overflow or respective owner

Related posts about c#

Related posts about regex