pulling an unknown string from the middle of two knowns

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a string...
abcdefghijklmnop

I know the 'abcdefg' and i know the 'jklmnop', but I dont know the >hi<.

How do I assign this >hi< to a string so that I can play with it later?
 
So, you are assuming: string s = prefix + stuff + suffix, and you want
stuff.
Something like:
string stuff = s.Substring(prefix.Length, s.Length-(prefix.Length
+suffix.Length);
 
Your a good man Fred, Thanks. I got it.


Fred Mellender said:
So, you are assuming: string s = prefix + stuff + suffix, and you want
stuff.
Something like:
string stuff = s.Substring(prefix.Length, s.Length-(prefix.Length
+suffix.Length);
 
hourlie wrote
I have a string...
abcdefghijklmnop

I know the 'abcdefg' and i know the 'jklmnop', but I dont know the >hi<.

How do I assign this >hi< to a string so that I can play with it later?

Use a regular expression:

Match match = Regex.Match("abcdefghijklmnop", "abcdefg(.*)jklmnop");
if (match.Success)
// now access match.Groups[1].Value to get to the inner string




Oliver Sturm
 
Back
Top