Wednesday, 14 August 2013

Extract portion of text in ASP.NET

Extract portion of text in ASP.NET

I need to extract of subset of a String using a pair of markers that would
be contained within it. For example, given the following String:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <!--extract-->Sed
nec luctus magna, ac tincidunt metus. Maecenas sodales iaculis ipsum sed
blandit.<!--/extract--> Quisque tincidunt nulla sapien, non faucibus
turpis aliquam at.
How can I extract everything in between and (but not the tags themselves)?
The String will be different lengths every time, but will always contain
the markers.
I've been messing with String.SubString() but am struggling to reliably
calculate the start/end indexes. Note that the start/end markers will
always have specific values to allow them to be located.
Thanks in advance.

No comments:

Post a Comment