[正确的数据格式]
22
00:06:12,167 --> 00:06:13,968
You a pervert?Ha....
That is....23
00:06:16,868 --> 00:06:22,267
My boys can see your panties.[错误的数据格式]
2200:06:12,167 --> 00:06:13,968You a pervert?23
00:06:16,868 --> 00:06:22,267
My boys can see your panties.
数据格式如上,错误的格式其实是多了空行!
怎么把这些空行处理掉,希望能给正则表达式!

解决方案 »

  1.   


                string str=@"2200:06:12,167 --> 00:06:13,968You a pervert?
    ";
                str=Regex.Replace(str,@"(\r\n)+","\r\n");
                Console.WriteLine(str);
      

  2.   


    那些空行是需要的[标号:如22, 只有一行]
    [时间:如00:06:12,167 --> 00:06:13,968, 只有一行]
    [内容:如My boys can see your panties. 可有多行,且允许空行]
    [空行: 这里必须也只能有一个空行]
      

  3.   

    不知道你要的是不是这种效果?string htmlContent = @"2200:06:12,167 --> 00:06:13,968You a pervert?23
    00:06:16,868 --> 00:06:22,267
    My boys can see your panties.
    ";
                string pattern = @"(\r\n){2,}";
                htmlContent = Regex.Replace(htmlContent, pattern,"\r\n",RegexOptions.IgnorePatternWhitespace);
    /*
    22
    00:06:12,167 --> 00:06:13,968
    You a pervert?
    23
    00:06:16,868 --> 00:06:22,267
    My boys can see your panties.
    */
      

  4.   

    标号:textBox1 \r\n
    时间:textBox2 \r\n
    内容:listBox1 \r\n
    consolen.writeLine("");空白行用些小小控件可以更好的实现你的需要。\r\n是回车吧
      

  5.   

    只为了替换空行,就替换 \r\n 就ok了,不知道你的空行是否还有其他可能,比如一行空格
      

  6.   

    [标号:如22, 只有一行]
    [时间:如00:06:12,167 --> 00:06:13,968, 只有一行]
    [内容:如My boys can see your panties. 可有多行,且允许空行]
    [空行: 这里必须也只能有一个空行]
    上面这是格式!!