Regular expression question

  • Thread starter Thread starter Evgeny.Br
  • Start date Start date
E

Evgeny.Br

Hi there,

Suppose i have string like:

string str="The Message Subject:bla bla bla bla. The Body: rerere
rerere";


Is there is some way to cut string beetween The Message Subject and
The Body, other then

string .IndexOf and all other string methods.

Maybe with regular expression in some way???

Thanks in advance.
 
Evgeny,

You could use Split method, something like:

string[] values = str.Split(new String(){"The Message Subject ", "The
Body"}, StringSplitOptions.None)

HTH
 
Hi,

Only if "The Message Subject" or the delimiter, ":" are constants or at least
if their current values are known at runtime. If both of these values cannot
be determined at runtime then no single expression will work because you won't
know the value on which to split the string.

It sounds to me like "The Message Subject" and "The Body" could frequently
change, but if you know of a specific delimiter that will always be present
then a Regex pattern could be written to do the parsing. Instead, you could
use the code from Sergey's response, given that you know the current values of
"The Message Subject" and "The Body" already.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top