Spliting Large String

  • Thread starter Thread starter - Steve -
  • Start date Start date
S

- Steve -

I have a string that contains something along the lines of this:

This is a body of an e-mail message. I have no idea how long it goes, how
it ends, etc.

------ Do not modify below ------
<query>filename.csv</query>

I need to split the string into two parts. The body of the message part,
and I need to extract the filename between the <query> brackets. What's the
best way to go about this? I was thinking I could find the index of "------
Do not modify below ------" but that seems like a flakey way to do it.
 
Well, you could us a regex, but that seems like unnecessary overkill. I
don't know what you mean exactly by "flakey", but using IndexOf to find the
<query> and the </query> and then Substring to get the part in between seems
straightforward enough to me. I would think any alternative you devised
would look just as "flakey" as IndexOf.
 
If you're only searching it once, I don't see anything wrong with using
IndexOf(). You might consider using regular expressions if you expect to
search more than once.
Tom Clement
Apptero, Inc.
 
Steve,

If you want to allow for the unlikely eventuality that your body also
contains the mark

"------ Do not modify below ------"

(ie. it occurs twice) then use the method LastIndexOf

Phil...
 
Back
Top