C# string replace
I want to replace ","
with a ;
in my string.
For example:
Change
"Text","Text","Text",
to this:
"Text;Text;Text",
I've been trying the line.replace( ... , ... )
, but can't get anything working properly.
Try this:
line.Replace("\",\"", ";")
The simplest way is to do
line.Replace(@",", @";");
Output is shown as below:
You need to escape the double-quotes inside the search string, like this:
string orig = "\"Text\",\"Text\",\"Text\"";
string res = orig.Replace("\",\"", ";");
Note that the replacement does not occur "in place", because .NET strings are immutable. The original string will remain the same after the call; only the returned string res
will have the replacements.
var str = "Text\",\"Text\",\"Text";
var newstr = str.Replace("\",\"", ";");