开发者

Split string by a complete string separator

I need to split a string, for example AAA@AAA_@#@BBBBBB@#@CCCCCC, using as separator the complete string "_@#@_". The result i'm looking for is:

[0] AAA@AAA

[1]

[2] BBBBBB

开发者_Go百科[2]

[3] CCCCCC

I'm doing the following:

char[] sep = FIELD_SEPARATOR.ToCharArray();
ArrayList result = new ArrayList();
string[] fields = line.Split(sep);

Where FIELD_SEPARATOR is the string "_@#@" The thing is that i'm getting 2 records for the first field, and the "@" char is deleted from them.

[0] AAA

[1] AAA

...

Is there a way to do it? I'm using .NET Framework 1.1

Thanks in advance!


This should also work for you:

string[] bits = Regex.Split("AA@AAA_@#@BBBBBB@#@CCCCCC", "@#@");


Does this not work?

string[] fields = line.Split(new string[] {"@#@"}, StringSplitOptions.None);


if,

string oldstring="AAA@AAA_@#@BBBBBB@#@CCCCCC";

then,

string[] parts = System.Text.RegularExpressions.Regex.Split(oldstring,"@#@");

This will give ,

parts[0]=AAA@AAA_

parts[1]=BBBBBB

parts[2]=CCCCCC

Will that Suffice...........


To be more correct

line.Split(new string[] { "@#@" }, StringSplitOptions.None)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜