Get part of the text (c#)

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

Guest

Hi y'all,
I have a beginner question in c#. I need to take part of a text, based on
tags. for example:

string test = "blah blah<!--start -->1 2 3 4<!--end--> blah blah";

I want to get whatever is between the start and end tags.
result = "1 2 3 4";

Can anyone help me pls!!!
Thanks ahead,
~Jay
 
Jay said:
Hi y'all,
I have a beginner question in c#. I need to take part of a text, based on
tags. for example:

string test = "blah blah<!--start -->1 2 3 4<!--end--> blah blah";

I want to get whatever is between the start and end tags.
result = "1 2 3 4";

Can anyone help me pls!!!
Thanks ahead,
~Jay

int start = test.IndexOf("<!--start -->")+("<!--start -->").Length;
string result = test.Substring(start,test.IndexOf("<!--end-->")-start);



--
Texeme Textcasting Technology
http://texeme.com

Indie Pop Rocks @ SomaFM
http://somafm.com/
 
Jay said:
I have a beginner question in c#. I need to take part of a text, based on
tags. for example:

string test = "blah blah<!--start -->1 2 3 4<!--end--> blah blah";

I want to get whatever is between the start and end tags.
result = "1 2 3 4";

Regex.Match(test, "<!--start -->(.*)<!--end-->").Group[1].Value
 
Back
Top