南航 温哥华:初学C#,如何实现将字符串“A,B,C”按逗号分隔存储?

来源:百度文库 编辑:神马品牌网 时间:2024/05/11 05:34:17
我记得好像是split,但是忘记了,哪位高手贴几行代码解决一下?
string strABC;
strABC="A,B,C";
然后以逗号分隔存储在数组中,就几行代码,高手赐教。

1
你是指 String.Split 方法吗?假如你有一个文件用于储存通讯录数据,每一行储存一个人的数据,例如:

First Name, Last Name, Age, Phone, Email, Address

那么当你把当前行读取到一个 string 变量后,你可以这样进行分割:

string currentLine = ...;
string[] items = currentLine.Split(new string[] { ", " }, StringSplitOptions.None);

上面那行分割后的结果是:

First Name
Last Name
Age
Phone
Email
Address

2
string a="1,2,3,4,5,6,7,8,9";
string[] b = a.Split(new Char[] { ',' });
for (int i = 0; i < b.Length; i++)
Console.WriteLine(b[i]);
Console.Read();

不过Split有n多overload还是看看msdn先