Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strip double quotes from a string in .NET

Tags:

c#

.net

vb.net

People also ask

How do you remove double quotes from a string?

To remove double quotes just from the beginning and end of the String, we can use a more specific regular expression: String result = input. replaceAll("^\"|\"$", ""); After executing this example, occurrences of double quotes at the beginning or at end of the String will be replaced by empty strings.

How can I remove extra double quotes from a string in C#?

The String. Replace() function has a string return type. If we want to remove quotes from a string, we can replace it will an empty string. We can specify that we want to replace the double quotes with "\"" .

How do you escape a quote from a string in C#?

C# Language Verbatim Strings Escaping Double Quotes Double Quotes inside verbatim strings can be escaped by using 2 sequential double quotes "" to represent one double quote " in the resulting string. var str = @"""I don't think so,"" he said. "; Console.

How can remove double quotes from string in MVC?

yourString = yourString. Replace("\"", string. Empty). Trim();


I think your first line would actually work but I think you need four quotation marks for a string containing a single one (in VB at least):

s = s.Replace("""", "")

for C# you'd have to escape the quotation mark using a backslash:

s = s.Replace("\"", "");

I didn't see my thoughts repeated already, so I will suggest that you look at string.Trim in the Microsoft documentation for C# you can add a character to be trimmed instead of simply trimming empty spaces:

string withQuotes = "\"hellow\"";
string withOutQotes = withQuotes.Trim('"');

should result in withOutQuotes being "hello" instead of ""hello""


s = s.Replace("\"", "");

You need to use the \ to escape the double quote character in a string.


You can use either of these:

s = s.Replace(@"""","");
s = s.Replace("\"","");

...but I do get curious as to why you would want to do that? I thought it was good practice to keep attribute values quoted?