我给某网站发送的POST请求,返回的内容应不包含HTML标记,但可以用“<!-- … -->”标记进行注释。返回信息如下(有2种情况验证正确和错误):
正确信息如下:
<!-- this is my registration code page. -->
<!-- my comments here -->
<!-- the line containing “KUQU_BEG_REG_CODE” signals the start of my single spaced registration code list -->
<!-- and the line containing “KUQU_END_REG_CODE” signals the end of my single spaced registration code list -->KUQU_BEGIN_REG_CODE
regCode1
regCode2
regCode3
KUQU_END_REG_CODE<!-- end of my unlock code page -->
错误信息入下:
<!-- this is my registration code page. -->
<!-- my comments here -->
<!-- the line containing “KUQU_BEG_REG_CODE” signals the start of my single spaced registration code list -->
<!-- and the line containing “KUQU_END_REG_CODE” signals the end of my single spaced registration code list -->KUQU_BEGIN_REG_CODE
ERR: errNumber
ERR: errNumber:ErrDescription(有可能是这样的,实际返回的只有1行,不是上面是就是这个)
KUQU_END_REG_CODE<!-- end of my unlock code page -->
我现在需要将
regCode、ERR: errNumber
或者ERR: errNumber:ErrDescription提取出来.
如果返回正确信息:
我需要将regCode1,regCode2,regCode3存在数组里面.
如果返回错误信息:
如果是返回的ERR: errNumber,我需要的是errNumber;
如果是返回的ERR: errNumber:ErrDescription,我需要把errNumber和ErrDescription分别放到2个变量里面去

解决方案 »

  1.   

    用正则  不过这两部分怎么区分 等高手了KUQU_BEGIN_REG_CODE 
    regCode1 
    regCode2 
    regCode3 

    KUQU_END_REG_CODE KUQU_BEGIN_REG_CODE 
    ERR: errNumber 
    ERR: errNumber

    KUQU_END_REG_CODE
      

  2.   

    regCode
    ERR:
    这两个是不是可以作为区分呢。
      

  3.   

    regCode
    ERR: 
    不可能同时出现
    返回要么是regCode
    要么是ERR:
      

  4.   

    先用正则表达式string regStr="(KUQU_BEGIN_REG_CODE)(\KUQU_End_REG_CODE)*KUQU_End_REG_CODE";
    把这一段提取出来,判断里面是否用ERR:就行了
      

  5.   

    上面正则打错了(KUQU_BEGIN_REG_CODE)([^KUQU_End_REG_CODE]*)(KUQU_End_REG_CODE)
      

  6.   

    //            string sReceive = @"
    //                KUQU_BEGIN_REG_CODE 
    //                regCode1 
    //                regCode2 
    //                regCode3 
    //                KUQU_END_REG_CODE 
    //                ";
                string sReceive = @"
                    KUQU_BEGIN_REG_CODE 
                    ERR: 123 
                    ERR: 123:ErrDescription(error in line 2314)
                    KUQU_END_REG_CODE 
                    ";
                string sReg = @"(?<=KUQU_BEGIN_REG_CODE)[\s\S]*(?=KUQU_END_REG_CODE)";
                Match match = Regex.Match(sReceive, sReg);
                string sCode = match.Value.TrimStart().TrimEnd();
                if (sCode.IndexOf("ERR:") == -1)  //success code
                {
                    string[] codeSet = Regex.Split(sCode, "\\s+");
                    Console.WriteLine(String.Join(",", codeSet));
                }
                else //error code
                {
                    sReg = @"(ERR:\s*(\S+))[\s]+(\1:ErrDescription\(([^\)]+)\))*";
                    match = Regex.Match(sCode, sReg);
                    Console.WriteLine("errCode:"+match.Groups[2].Value);
                    Console.WriteLine("ErrDescription:" + match.Groups[4].Value);
                }
      

  7.   

    error code
    改一下
    sReg = @"(ERR:\s*(\S+))[\s]*(\1:ErrDescription\(([^\)]+)\))*";