carrot1983 发表于 2015-9-17 00:02:22

如何分割字符串列表并取出一部份

{"Key1,a,b,c,e" , "Key2,a,b,c,e,d" , "Key2,a,b,a,1,2,3" ...}
   
string[] typ = s.Split(','); //分割出来的是数组,数组我查了一下删除元素,只能重建。


List<string>

用泛型,感觉有希望,就是写不正确。请指点一二。

现在是想得到这样的结果:就是去掉第一个元素。保留后面的。

{"a,b,c,e" , "a,b,c,e,d" , "a,b,a,1,2,3" ...}



{{"a“”b“”c“”e"} , {"a“”b“”c“”e“”d“} , "a“”b“”a“”1“”2“”3" ...}



ivde 发表于 2015-9-17 23:33:18

好像楼主是alisp惯性思维

carrot1983 发表于 2015-9-18 08:47:02

是的,表的思维定式了,还得楼上,多指点一二,转变到C#的思维,
面象对象的话,怎么处理才是合适的。

carrot1983 发表于 2015-9-18 08:56:34

这是根据表的思路写的。

         //创建字符串集合
            ArrayList types = new ArrayList();
            ArrayList values = new ArrayList();
            //取得数组的第一个
            foreach (string s in items)
            {
                //分割成数组
                string[] typ = s.Split('\t');
                //收集第一个
                types.Add(typ);
                //以下取得剩余的集合
                ArrayList l1 = new ArrayList(typ);
                //移除第一项
                l1.RemoveAt(0);
                //添加数组
                values.Add(l1);
            }

ivde 发表于 2015-9-18 11:57:45

5.int IndexOf()               返回指定的字符或字符串在当前字符串中的位置
8.string Replace(string,string)   字符串替换
9.string Remove(int,int)               从指定位置开始删除指定个数的字符
11.stringSubString(int,int)          返回从指定位置开始指定个数的字符串

carrot1983 发表于 2015-9-18 12:36:33

ivde 发表于 2015-9-18 11:57 static/image/common/back.gif
5.int IndexOf()               返回指定的字符或字符串在当前字符串中的位置
8.string Replace(string,s ...

谢谢,这些只不过是处理字符串,最终需要的是列表。

雪山飞狐_lzh 发表于 2015-9-30 09:42:12

泛型列表可以用数组作为参数新建

carrot1983 发表于 2015-9-30 10:29:19

雪山飞狐_lzh 发表于 2015-9-30 09:42 static/image/common/back.gif
泛型列表可以用数组作为参数新建

狐哥,终于出现了,后面,自己也捣鼓出来了。谢谢指点。
页: [1]
查看完整版本: 如何分割字符串列表并取出一部份