字符串遍历处理

jy02418676 2010-09-26 01:21:43
如 string i='12,13,14,234,23'

我需要做成 '12','13','14','234','23’

有什么好办法么,我想到的办法太麻烦了,效率太低
...全文
209 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
kensouterry 2010-09-26
  • 打赏
  • 举报
回复
呵呵,帮你整合一下。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Collections;

namespace ConsoleApplication1
{
class Program
{
string[] arraySplit;

public Program()
{
string i = "12,13,14,234,23";

arraySplit = i.Split(new string[1] { "," }, StringSplitOptions.RemoveEmptyEntries);
//arraySplit变量里面就存放了你需要的字符串
//Display the split string in Console.
for (int j = 0; j < arraySplit.Length; j++)
{
Console.WriteLine("{0}:{1}", j, arraySplit[j]);
}
}

static void Main()
{
Program p1 = new Program();

Console.ReadLine();
}
}

}
Wilson_Zhong 2010-09-26
  • 打赏
  • 举报
回复
string i='12,13,14,234,23';
string[] iStr=i.split(',');

iStr[i]即为'12','13','14','234','23’
铛铛 2010-09-26
  • 打赏
  • 举报
回复
string i='12,13,14,234,23'

这是什么东西,字符吗?这么长?

如果是string i=“12,13,14,234,23”;
string[] strs = i.Split(',');
hongjiaoli 2010-09-26
  • 打赏
  • 举报
回复
string i ="12,13,14,234,23";
string[] tem = i.split(',');
liuh6 2010-09-26
  • 打赏
  • 举报
回复
string []iList_=i.Split(',');

数据里的就是你要的东西..
lqkankan 2010-09-26
  • 打赏
  • 举报
回复
没明白 啥意思


string i ="12,13,14,234,23";
string[] tem = i.split(',');
for(int j=0;i<tem.length;j++)
//do what you want


string a = "'12','13','14','234','23’";//这样?
//还是
string b = "12','13','14','234','23"; //这样?

wuyq11 2010-09-26
  • 打赏
  • 举报
回复
List<string> list = new List<string> { "1", "2", "3" };
string result = string.Join(",", list.ConvertAll(delegate(string s) { return string.Format("'{0}'", s); }).ToArray());

string str="";
str = String.Join("','",str.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries));
str = "'" + str + "'";
threenewbee 2010-09-26
  • 打赏
  • 举报
回复
Split函数。

111,129

社区成员

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

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

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