在字符串上拆分字符串而不是字符

时间:2021-12-17 21:39:04

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

我想在html标签上拆分gridview行。我怎样才能在C#中做到这一点?

e.row.cells[1].Text.Split("htmltag")

7 个解决方案

#1


16  

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.

但请注意上面的StrixVaria的评论。解析HTML是令人讨厌的,所以除非你是专家卸载工作给别人。

#2


4  

In addition to string.split, you can use Regex.Split (in System.Text.RegularExpressions):

除了string.split之外,您还可以使用Regex.Split(在System.Text.RegularExpressions中):

string[] lines = Regex.Split(.row.cells[1].Text, "htmlTag");

#3


3  

Try this:

e.Row.Cells[1].Text.Split( new string[] { "</b>" }, StringSplitOptions.None );

#4


3  

One of the overloads of String.Split takes a String[] and a StringSplitOptions - this is the overload you want:

String.Split的一个重载需要String []和StringSplitOptions - 这是你想要的重载:

e.row.cells[1].Text.Split(new string[] { "</b>" }, StringSplitOptions.None);

or

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

depending on what you want done with empty entries (ie when one delimiter immediately follows another).

取决于你想要用空条目做什么(即当一个分隔符紧跟另一个分隔符时)。

However, I would urge you to heed @StrixVaria's comment...

但是,我会敦促你注意@ StrixVaria的评论......

#5


1  

To split a string with a string, you would use this..

要用字符串拆分字符串,你可以使用它。

string test = "hello::there";
string[] array = test.Split(new string[]{ "::" }, StringSplitOptions.RemoveEmptyEntries);

#6


0  

Use one of the overloads of string.Split(...). But as the comment says, perhaps another method of doing it would be preferrable.

使用string.Split(...)的重载之一。但正如评论所说,也许另一种做法是优先考虑的。

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

#7


0  

This is one of those times where I go old school VB and use just use:

这是我去旧学校VB并使用的时间之一:

Split(expression, delimiter)

or in C#

或者在C#中

Microsoft.VisualBasic.Strings.Split(expression,delimiter)

#1


16  

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.

但请注意上面的StrixVaria的评论。解析HTML是令人讨厌的,所以除非你是专家卸载工作给别人。

#2


4  

In addition to string.split, you can use Regex.Split (in System.Text.RegularExpressions):

除了string.split之外,您还可以使用Regex.Split(在System.Text.RegularExpressions中):

string[] lines = Regex.Split(.row.cells[1].Text, "htmlTag");

#3


3  

Try this:

e.Row.Cells[1].Text.Split( new string[] { "</b>" }, StringSplitOptions.None );

#4


3  

One of the overloads of String.Split takes a String[] and a StringSplitOptions - this is the overload you want:

String.Split的一个重载需要String []和StringSplitOptions - 这是你想要的重载:

e.row.cells[1].Text.Split(new string[] { "</b>" }, StringSplitOptions.None);

or

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

depending on what you want done with empty entries (ie when one delimiter immediately follows another).

取决于你想要用空条目做什么(即当一个分隔符紧跟另一个分隔符时)。

However, I would urge you to heed @StrixVaria's comment...

但是,我会敦促你注意@ StrixVaria的评论......

#5


1  

To split a string with a string, you would use this..

要用字符串拆分字符串,你可以使用它。

string test = "hello::there";
string[] array = test.Split(new string[]{ "::" }, StringSplitOptions.RemoveEmptyEntries);

#6


0  

Use one of the overloads of string.Split(...). But as the comment says, perhaps another method of doing it would be preferrable.

使用string.Split(...)的重载之一。但正如评论所说,也许另一种做法是优先考虑的。

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

#7


0  

This is one of those times where I go old school VB and use just use:

这是我去旧学校VB并使用的时间之一:

Split(expression, delimiter)

or in C#

或者在C#中

Microsoft.VisualBasic.Strings.Split(expression,delimiter)