tags:

views:

45

answers:

3

hi

how to remove only one char (") if there two("") from the string in C# (Regex )

ex.:

123"43""343"54"" ==>  123"43"343"54"

"abc""def"gh""i  ==>  "abc"def"gh"i

thank's in advance

+4  A: 

You don't need regex for this. Just search for the sub-string "" and replace it with "

codaddict
See http://en.csharp-online.net/CSharp_Regular_Expression_Recipes%E2%80%94Replacing_Characters_or_Words_in_a_String for examples
Peter Schuetze
+2  A: 

someString.Replace(@"""""",@""""); should work, shouldn't it?

while (someString.IndexOf(@"""""") > -1)
{
   someString = someString.Replace(@"""""",@"""");
}
Anthony Pegram
cool !!, thank's !and how i can remove " from the begin and the end of a string ?
Gold
You don't need the while loop. String.Replace with replace all instances.
juharr
@juharr, this is coding for the scenario where there are instances of 2 *or more* quotes in a row.
Anthony Pegram
A: 
Regex regExp = new Regex("\"\"");
string test = "123\"\"123\"\"123";
string tempTxt = regExp.Replace(test, "\"");

Something like this? But yeah, i think Regex isn't good choise here.

Andrew