Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove char (") from the begin and the end of a string?

Tags:

c#

regex

how to remove char (") from the begin and the end of a string ?

ex: "1234"567" ==> 1234"567

thank's in advance

like image 893
Gold Avatar asked Apr 14 '10 18:04

Gold


1 Answers

myString = myString.Trim('"');

http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx

Note that this will remove any amount of quotes at the beginning or the end of the string. If you only want to remove at most one from each end, see Anthony Pegram's answer. Or do it with regex:

myString = Regex.Replace(myString, "^\"|\"$", "");
like image 54
Matti Virkkunen Avatar answered Sep 19 '22 06:09

Matti Virkkunen