开发者

split a string in to multiple strings

123\r开发者_StackOverflow社区\n456t\r\n789

How can i split the string above in to multiple strings based on the string text .split has only over load that takes char :(


string.Split has supported an overload taking an array of string delimiters since .NET 2.0. For example:

string data = "123text456text789";
string[] delimiters = { "text" };
string[] pieces = data.Split(delimiters, StringSplitOptions.None);


use string.split("text"), hope it will help.


I believe you want to split 123, 456, 789 as you have \r\n after them.

Easiest way I see is

string textVal = "123\r\n456t\r\n789";

textVal = textVal.replace("\r", "").replace("\n",",");

string arrVal[] = textVal.split(',');

Now you have arrVal containing 123, 456, 789.

Happy coding


String.Split supports also an array of strings. In your case you can do:

string s = "123\r\n456t\r\n789";
string[] parts = s.Split(new string[] {"\r\n"}, StringSplitOptions.None);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜