So here the situation.
I have multiple strings that begin and end with a random amount of spaces. The problem is the string contains multiple words so I can't just replace(" ","") so for example.
" apple red "
' orange orange '
' pear grapes '
' turnship turn it over here '
and I would want to return.
'apple red'
'orange orange'
'pear grapes'
'turnship turn it over here '
Try
yourString.Trim();
See: http://msdn.microsoft.com/en-us/library/aa904317(v=vs.71).aspx
Use
String.Trim()
Assuming the quotes are really in there, then you want to use a regular expression:
Simply replace it with:
So:
What about String.Trim()?
http://msdn.microsoft.com/en-us/library/system.string.trim.aspx
Returns a new string in which all leading and trailing occurrences of a set of specified characters from the current String object are removed.