例:
str1=“安徽”;
str2=“[天津,吉林,安徽][福建,湖南,四川]”;说明 :这个可能是两个【】括起来也可能是多个 但是 安徽只会在 str2中出现一次或者不出现 ,出现的话 取出是在第几个 【】中?

解决方案 »

  1.   

    上次你就似乎问了一个比较奇特的问题        string str1 = "安徽";
            string str2 = "[天津,吉林,安徽][福建,湖南,四川]";
            int i = 0;
            Regex.Replace(str2, @"(\[[^\[]+?)" + str1, delegate(Match e)
            {
                i++;
                return e.Value;
            });
            Console.WriteLine(i);
      

  2.   

            string str1 = "安徽";
            string str2 = "[天津,吉林][福建,湖南,四川][安徽]";
            int i = 0;
            Regex.Replace(str2, @"(\[[^\[]+?)+(?!=" + str1 + ")", delegate(Match e)
            {
                i++;
                return e.Value;
            });
            Console.WriteLine(i);
      

  3.   


                string str1="安徽";
                string str2="[天津,吉林,安徽][福建,湖南,四川]";            string[] splittedString = str2.Split(new char[] { ']'});
                int res = -1;
                for (int i = 0; i< splittedString.Count(); ++i)
                {
                    if (splittedString[i].Contains(str1))
                    {
                        res = i;
                        break;
                    }            }         
    res就是你想要的值, -1是不包含。
      

  4.   

    5L:
    splittedString.Count()需要using什么?
      

  5.   


    splittedString  这个是一个数组的命名,