C#如何将字符串分割成数组

sexcrime 2014-03-14 04:09:15
string str ="123|456|789";
|作为分割符号,如何分割成 123 456 789集合的数组?split试了为何不行?
...全文
1218 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Regan-lin 2014-03-14
  • 打赏
  • 举报
回复
引用 3 楼 xyd573417994 的回复:
TextBox txtCon = txtCont1; string txtConV = txtCon.Text; //你要分割的值 可在最后+一个分割符 string domo =txtGValue.Text;//分割符 int Strcount = 0; string strconValue = ""; for (int i = 0; i < txtConV.Length; i++) { strconValue = txtConV.Substring(i, 1); if (strconValue == domo) { Strcount++; } } int domoLive = 0; try { for (int i = 1; i <= Strcount + 1; i++) { if (i <= 7) { int num1 = txtConV.IndexOf(domo, domoLive); int sms = num1 - domoLive; if (sms > 0) { string sid = txtConV.Substring(domoLive, sms); //txtCont2.Text = sid; this.Controls["txtCont" + (i + 1).ToString()].Text = sid; //分别显示控件中 domoLive = num1 + domo.Length;//分割符的索引 下次分割以此开始 } } } } catch (Exception ex) { MessageBox.Show(ex.Message); }
牛刀割小j
大湿级 2014-03-14
  • 打赏
  • 举报
回复
TextBox txtCon = txtCont1; string txtConV = txtCon.Text; //你要分割的值 可在最后+一个分割符 string domo =txtGValue.Text;//分割符 int Strcount = 0; string strconValue = ""; for (int i = 0; i < txtConV.Length; i++) { strconValue = txtConV.Substring(i, 1); if (strconValue == domo) { Strcount++; } } int domoLive = 0; try { for (int i = 1; i <= Strcount + 1; i++) { if (i <= 7) { int num1 = txtConV.IndexOf(domo, domoLive); int sms = num1 - domoLive; if (sms > 0) { string sid = txtConV.Substring(domoLive, sms); //txtCont2.Text = sid; this.Controls["txtCont" + (i + 1).ToString()].Text = sid; //分别显示控件中 domoLive = num1 + domo.Length;//分割符的索引 下次分割以此开始 } } } } catch (Exception ex) { MessageBox.Show(ex.Message); }
练白龙 2014-03-14
  • 打赏
  • 举报
回复
怎么不行啊? 报错还是数组里没有值啊
  • 打赏
  • 举报
回复
string[] _list="123|456|789".Split('|');

110,538

社区成员

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

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

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