C# 按 ,将字符串分割成片段 片段们存入字符串数组中

hinada99 2010-12-10 02:43:04

如题
public static string[] GetPieceBetweenComma(string txt)
{

}

txt="16,20,abc,hello,3x"

返回的结果要求是
string[] a

a[0]=16
a[1]=20
a[2]=abc
a[3]=hello
a[4]=3x

在线等C#高手解答
...全文
413 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
kissdeath 2010-12-10
  • 打赏
  • 举报
回复
不好意思,split方法用错了
应该是如下:
string s = "16,20,abc,hello,3x";
string[] str;
str = s.Split(new char[] { ','});
for (int i = 0; i < str.Length; i++)
{

}
  • 打赏
  • 举报
回复

split是正解

只是楼主为什么在问题前后加个”太阳“呢
kissdeath 2010-12-10
  • 打赏
  • 举报
回复
string s = "16,20,abc,hello,3x";
string[] str;
str= s.Split(new char[',']);
for (int i = 0; i < str.Length; i++)
{
}
rabbitlzx 2010-12-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 shiyuyao1987 的回复:]
return txt.split(',');
[/Quote]
就这么简单的问题居然100分
Return门徒 2010-12-10
  • 打赏
  • 举报
回复
split
Return门徒 2010-12-10
  • 打赏
  • 举报
回复

string str[]="16,20,abc,hello,3x".scipt(',')


shiyuyao1987 2010-12-10
  • 打赏
  • 举报
回复
return txt.split(',');

110,500

社区成员

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

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

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