我想用c#消除一段字符串中的空格,如下所示
<input type="button" value="OK"/> </td>  </tr>我想处理的效果就是消除反括号与正括号之间的空格,其他的地方不管,最终得到
<input type="button" value="OK"/></td></tr>各位达人,能否给个解决办法,不甚感激···

解决方案 »

  1.   

    可能得用正则表达式,匹配“> <”这两个符号包含空格的情况,替换为"><"
      

  2.   

    使用正则,
    <[^>]*>将匹配的加起来即可,只不过如果是<input type="button" value="OK"/> </td>  test</tr> 这样的,自己还得增加处理。
      

  3.   

    就是对一个字符串进行消除空格的操作,给出一段比较完整的字符串<tr>  <td>意见</b></td>  <td colspan="3"><textarea rows="4" cols="55">
    </textarea></td>
            </tr>
    希望将>与<之间的空格消除掉,对于其他的页面元素如<textarea rows="4">这中间的空格不管,只消除><之间的空格,最终得到
    <tr><td>意见</b></td><td colspan="3"><textarea rows="4" cols="55"></textarea></td></tr>
      

  4.   

    遍历?替换> < 为><?
      

  5.   


    '遍历?替换> < 为 ><?
      

  6.   


    string sContent = @"<tr>  <td>意见</b></td>  <td colspan='3'><textarea rows='4' cols='55'>
    </textarea></td>
            </tr>
    ";
                string value = "";
                Regex regex = new Regex(@"(?<name><[^>]*>)(?<info>([\s|\S]*?(?=<))*)", RegexOptions.Multiline | RegexOptions.Compiled);
                MatchCollection matches = regex.Matches(sContent);
                foreach (Match match in matches)
                {
                    if (match.Groups["name"] != null)
                    {
                        value += match.Groups["name"].ToString().Trim();
                    }
                    if (match.Groups["info"] != null)
                    {
                        value += match.Groups["info"].ToString().Trim();
                    }
                }
    value就是你要的结果