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.
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.
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.
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.
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
string inputStr = "'some string'";
string outputStr = inputStr.Trim('\'')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With