Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove single quote from start of the string and end of the string

Tags:

string

c#

I want to remove quote from starting of the string and end of the string. But my existing code is removing all quotes from the string. I tried to replace with Trim() method. But no hopes.

My code here

result = value.Replace("'", "").Split(',').ToList();

I tried the following also,

result = value.TrimStart(Convert.ToChar("'"))
              .TrimEnd(Convert.ToChar("'"))
              .Split(',')
              .ToList();

Please give me the proper way to do this.

like image 475
PoliDev Avatar asked Jan 04 '17 06:01

PoliDev


People also ask

How do I remove a single quote from a string?

Therefore, to remove single quote from string column, we can use gsub function by defining the single quote and replacing it with blank(not space) as shown in the below examples.

How do I remove single quotes from the beginning and end of a string in Python?

Using the replace() function to remove single quotes from string in Python. The replace() function simply substitutes one sub-string with another, both of which are taken as arguments within the function. The single quotes can be taken as the substring to replace and it can be substituted with a simple space.

How do you remove double quotes from the beginning and end of a string in Python?

Using the strip() Function to Remove Double Quotes from String in Python. We use the strip() function in Python to delete characters from the start or end of the string. We can use this method to remove the quotes if they exist at the start or end of the string.


2 Answers

You can try .Trim() like the following:

string inputStr = "'some string'";
string outputStr = inputStr.Trim(new char[]{(char)39});

Where (char)39 represents ', and the .Trim() will remove the first and last ' from the string; You can try like this as well:

string outputStr = inputStr.Trim('\'');

You can take a look into this Example

like image 154
sujith karivelil Avatar answered Oct 17 '22 01:10

sujith karivelil


string inputStr = "'some string'";
string outputStr = inputStr.Trim('\'')
like image 34
Gk_999 Avatar answered Oct 17 '22 01:10

Gk_999