kw_uh97 said:
I would like to extract a string that has a single qoutes at the beginning
and end like the 'mystring' how would I go about getting the mystring to
appear?
Thanks in Advance for any help
To extract mystring from the 'mystring' in the lines above you typically use
RegEx expressions.
using System.Text.RegularExpression;
...
Regex expression = new Regex("'[^']*'");
Match match = expression.Match("some string with 'apples' and 'bananas'");
string result = match.Value.Trim(new char[] { '\'' });
The above code match will contain 'apples', which you can strip the ' from
in numerous ways. Calling match.NextMatch() will give you 'orange' etc.
You can also do it without RegEx
string s = "some string with 'apples' and 'bananas'";
int start = s.IndexOf('\'') + 1;
int end = s.IndexOf('\'', start);
string result = s.Substring(start, end - start);
But this method may cause exceptions if you are missing a '