I wanted to remove double quotes from a string using C#, How can I do that easily and efficiently?
For Example, I have string : "-10,20", how to get output -> -10,20
Here are few ways to remove double quotes from string using C#
var yourString= "-10,20";
yourString = yourString.Replace('"', ' ').Trim();
OR
Using .Trim
yourString= yourString.Trim('"');
OR
yourString=yourString.Replace("\"", "");
Any of the above solutions should work.
You can simply use Replace
method in C#
yourString = yourString.Replace("\"", string.Empty).Trim();
We have added "\" (backslash) before double quotes to escape the quotation mark.
Simply try Trim() in C#
using System;
public class Program
{
public static void Main()
{
var str = "\"Add doublequotes\"";
Console.WriteLine(str);
//remove double quotes
Console.WriteLine(str.Trim('"'));
}
}
Output:
"Add doublequotes"
Add doublequotes
Fiddle:https://dotnetfiddle.net/oa7Kg8
That should work.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly