这个是.net2003 上关于c#的split用法
using System;public class StringSplit2 {
public static void Main() { string delimStr = " ,.:";
char [] delimiter = delimStr.ToCharArray();
string words = "one two,three:four.";
string [] split = null; Console.WriteLine("The delimiters are -{0}-", delimStr);
for (int x = 1; x <= 5; x++) {
split = words.Split(delimiter, x);
Console.WriteLine("\ncount = {0,2} ..............", x);
foreach (string s in split) {
Console.WriteLine("-{0}-", s);
}
}
}
}
在这一段
for (int x = 1; x <= 5; x++) {
split = words.Split(delimiter, x);
有2个问题,第一,这样为什么就能使用
split[0],split[1]类似的数组单元了,已经赋值了么?
第二,为什么x要小于等于5。
我是一个菜鸟,麻烦各位高手说的时候不要太专业,不然我真的不太懂,顺便祝愿各位元旦快乐,在这样的时间还能看论坛。
using System;public class StringSplit2 {
public static void Main() { string delimStr = " ,.:";
char [] delimiter = delimStr.ToCharArray();
string words = "one two,three:four.";
string [] split = null; Console.WriteLine("The delimiters are -{0}-", delimStr);
for (int x = 1; x <= 5; x++) {
split = words.Split(delimiter, x);
Console.WriteLine("\ncount = {0,2} ..............", x);
foreach (string s in split) {
Console.WriteLine("-{0}-", s);
}
}
}
}
在这一段
for (int x = 1; x <= 5; x++) {
split = words.Split(delimiter, x);
有2个问题,第一,这样为什么就能使用
split[0],split[1]类似的数组单元了,已经赋值了么?
第二,为什么x要小于等于5。
我是一个菜鸟,麻烦各位高手说的时候不要太专业,不然我真的不太懂,顺便祝愿各位元旦快乐,在这样的时间还能看论坛。
Arguments
stringObj
Required. The String object or literal to be split. This object is not modified by the split method.
separator
Optional. A string or an instance of a Regular Expression object identifying one or more characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
limit
Optional. A value used to limit the number of elements returned in the array.
Res
The result of the split method is an array of strings split at each point where separator occurs in stringObj. The separator is not returned as part of any array element.
第二,x要小于等于5是自定义的 没什么特别的含义,只是规定想返回多少个长度的string [] 数组。split(char[],int)第二个参数是返回数组的长度。