看看这个字符串怎么截取

67676373 2010-09-20 10:02:11
"[A1]\n[A2]\n[A3]\n[A4]"


我想按照\n 来截取

比如 第一个\n 后的所有内容 ,第二个\n后的所有内容

其中 [A1][A2][A3][A4] 的长度是变化的。

如果不考虑用split分成数组。。

有没有简洁点的方法?

...全文
104 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
-过客- 2010-09-20
  • 打赏
  • 举报
回复
try...

string test = "[A1]\n[A2]\n[A3]\n[A4]";
Regex reg = new Regex(@"(?s)\n(?=(.+))");
MatchCollection mc = reg.Matches(test);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups[1].Value + "\n----------------------\n";
}
wuyq11 2010-09-20
  • 打赏
  • 举报
回复
string str=""[A1]\n[A2]\n[A3]\n[A4]";
foreach(string s in str.Split(new string[]{"\n"},StringSplitOptions.RemoveEmptyEntries))
{}
threenewbee 2010-09-20
  • 打赏
  • 举报
回复
s = "[A1]\n[A2]\n[A3]\n[A4]";
ArrayList l = new ArrayList();
while (s.IndexOf("\n") == 0)
{
l.Add(s.SubString(s.IndexOf("\n") + 1));
s = s.SubString(s.IndexOf("\n") + 1);
}
foreach (String s in l)
{
Console.WriteLine(s);
}
aofengdaxia 2010-09-20
  • 打赏
  • 举报
回复
IndexOf("\n");

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧