Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to trim a single quote i.e. ' from string start and from end.
Thanx in Advance
Posted

You could have figured this out yourself by now, by looking at the methods that the string class has or by doing a quick search.

There are actually a set of function to trim chars off a string, these are

Trim() - Removes all leading and trailing white space
Trim(char[]) - Removes all leading and trailing occurrences of the characters specified
TrimEnd(char[]), TrimStart(char[]) - same as Trim but only on the start, or end of the string

MSDN - String[^]
 
Share this answer
 
Comments
zaki_8279025 18-Nov-10 22:52pm    
Thnx It works fine
This might require a little more explanation for it to be clear what it is that you want to do.

But, in case you mean exactly what you have written, two options spring to mind

1. Look up String.Remove(int32, int32)[^] on MSDN

2. Look up String.Replace(char/string, char/string)[^] on MSDN.

You should only use the second option if you can guarantee thet the quotes that you want to remove are the only ones.
 
Share this answer
 
Elaborating on SK, here is the implementation I believe you are looking for:

MIDL
string e = "'REMOVE FRONT ' AND BACK '";
e.Trim('\'');
 
Share this answer
 
C#
string e = "'REMOVE FRONT ' AND BACK '";
e.Replace(e,"'","");
 
Share this answer
 
Comments
Ron Beyer 18-Nov-13 18:25pm    
This will remove all of them, not just the front and back ones.
CHill60 18-Nov-13 18:43pm    
Reason for my downvote... your answer does not solve the problem as stated (front and back only) and the question is 3 years old and already adequately answered

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900