比如:
string a = "abcdefgabcdefgabcdefg";
我想取出所有的fg字串并存入数组变量中。
应该怎么做呢?谢谢!

解决方案 »

  1.   

    string a = "abcdefgabcdefgabcdefg";
            string item = "fg";
            
            int startindex = 0;
            int index = a.IndexOf(item, startindex);
            List<string> items = new List<string>();
            while(index > -1)
            {
                startindex = index + 1;
                items.Add(item);
                if(startindex < a.Length)
                {
                    index = a.IndexOf(item, startindex);
                }
            }
      

  2.   

    感谢zhujiazhi,唉,脑子转不过来了。结帖了。