Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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...
Posted
Updated 16-Jan-11 23:11pm
v7

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

for details, see Abhinav S' reply.

Cheers
 
Share this answer
 
Comments
venkatrao palepu 17-Jan-11 6:15am    
Thank you so much

it's working fine...
Dalek Dave 14-Dec-11 4:19am    
Spot on.
Try something like -

MIDL
Regex r = new Rexgex(@\"\\s+\");
inputstring = r.Replace(inputstring, " ");
 
Share this answer
 
Comments
Estys 17-Jan-11 4:54am    
I don't think thats what he wants.
He want multiple spaces between a close < /..> and open <..> tag replaced.
venkatrao palepu 17-Jan-11 5:01am    
i want if any no.of spaces between "> <" ,replace only those by single space
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;
    }

Thanks
 
Share this answer
 
while (strkeywords.Contains(" ")) strkeywords = strkeywords.Replace(" ", " ");
 
Share this answer
 
Comments
Pramod Harithsa 14-Dec-11 4:11am    
this thread is almost an year old!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900