如题,判断某字符串是否匹配 AABB(指连续出现4个字符,前2个相同,后两个相同),举例:
1、SLoi  不匹配
1、1123  不匹配
2、DD11  匹配
3、KKKK  匹配
在线等待!

解决方案 »

  1.   

    这个还用?str【0】==str【1】 and str【2】=str【3】
      

  2.   

    1楼想的过于简单,因为模式有很多,比如AAAB,ABBB,ABAB
      

  3.   

    try...//如果是判断包含
    (.)\1(.)\2
    //如果是判断整个字符串规则
    ^(.)\1(.)\2$
      

  4.   

    以此类推
    //AABB
    (.)\1(.)\2
    //AAAB
    (.)\1\1.
    //ABBB
    .(.)\1\1
    //ABAB
    (.)(.)\1\2以上都是认为A和B可以相同的,如果A和B要求不同//AABB
    (.)\1((?!\1).)\2
    //AAAB
    (.)\1\1(?!\1).
    //ABBB
    (.)((?!\1).)\2\2
    //ABAB
    (.)((?!\1).)\1\2
      

  5.   


    using System;
    using System.Collections.Generic;
    using System.Text;namespace Test
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = "aabb";
                char[] c = str.ToCharArray(0,str.Length);
                if (c[0] == c[1] && c[2] == c[3])
                {
                    Console.WriteLine("正确");
                }
                else
                {
                    Console.WriteLine("错误");
                }
                Console.ReadLine();
            }
        }
    }只会这办法