如何用单个空格代替特定的多个空格...? [英] How to replace particular many spaces by single space...?

查看:102
本文介绍了如何用单个空格代替特定的多个空格...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

如何用单个空格替换尖括号之间的特定多个空格
这是我的

Hello All

How to replace particular multiple spaces between angle brackets by a single space
This is my

inputstring=<ol>       <li>one </li>         <li>one       two  </li>  <li>three</li></ol>



我想要的是介于>  <"之间任何空格都来了,用
替换那些空格 > <"(单个空格)
其余字符串应相同

我想要这样的输出



What i want is in between ">     <" any spaces come,replace those by
"> <"(single space)
remaining string should be same

i want output like this

<ol> <li>one </li><li>one       two  </li> <li>three </ol>



请帮帮我..


在此先感谢...



please help me..


Thanks in advance...

推荐答案

要进行搜索的正则表达式为> \ s {2,}<".

有关详细信息,请参见Abhinav S''答复.

干杯
The regular expression to serch for would be ">\s{2,}<".

for details, see Abhinav S'' reply.

Cheers


尝试类似-

Try something like -

Regex r = new Rexgex(@\"\\s+\");
inputstring = r.Replace(inputstring, " ");


这是我为您构建的,肯定会帮助您解决问题.

This is what I constructed for you will definitely help you to solve your problem.

protected void Page_Load(object sender, EventArgs e)
    {
        Regex regex = new Regex(@"\>\s+\<");
        string str = "<ol>       <li>one </li>         <li>one       two  </li>  <li>three</li></ol>";
//replacing multiple space with single space
str = regex.Replace(str, new MatchEvaluator(Replacingit));

    }
    public string Replacingit(Match match)
    {
        string temp = match.Value;
//loop until remains single space.
        while (temp.Contains("  "))
        {
            temp = temp.Replace("  ", " ");
        }
        return temp;
    }


谢谢


这篇关于如何用单个空格代替特定的多个空格...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆