How to remove double quotes from string using C#?


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

 


Asked by:- Vinnu
2
: 14967 At:- 8/16/2019 12:35:50 PM
C# remove double quotes string







3 Answers
profileImage Answered by:- pika

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.

2
At:- 8/21/2019 11:46:31 AM Updated at:- 11/15/2022 7:52:27 AM
Thanks for correct answer and all alternatives. 0
By : Vinnu - at :- 8/29/2019 3:05:42 PM


profileImage Answered by:- neena

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.

1
At:- 6/1/2021 3:41:22 PM
.Replace is easy and quick. 0
By : pika - at :- 6/3/2022 9:13:42 AM


profileImage Answered by:- jaiprakash

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.

0
At:- 11/15/2022 2:38:55 PM Updated at:- 11/15/2022 2:39:09 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use