Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split a string on a string not a character

Tags:

I want to split a gridview row on an html tag. How can i do this preferably in C#??

e.row.cells[1].Text.Split("htmltag") 
like image 395
Eric Avatar asked Jan 22 '10 15:01

Eric


1 Answers

Yes. Use the overload

String.Split(String[], StringSplitOptions) 

or

String.Split(String[], int, StringSplitOptions) 

Example:

var split = e.row.cells[1].Text.Split(                 new[] { "</b>" },                 StringSplitOptions.RemoveEmptyEntries             ); 

But do heed StrixVaria's comment above. Parsing HTML is nasty so unless you're an expert offload that work to someone else.

like image 136
jason Avatar answered Oct 04 '22 04:10

jason