tags:

views:

76

answers:

4

I am parsing html page now any of string comes from html page I want to seprate each word with some seprator like if string comes from html page FUTIDX 26FEB2009 NIFTY 0 and I want the string like ////FUTIDX////26FEB2009////NIFTY////0.

In short any of string is there I want to insert //// for each word in the string.

I have tried str.Replace(" ","΄////") but if I insert with string FUTIDX 26FEB2009 NIFTY 0 it gives the result like ///////FUTIDX////26FEB2009////NIFTY 0/////// but I want like ////FUTIDX////26FEB2009////NIFTY 0//// means at each place where there is spaces I want to replace "////" but if there is more space between words then also there should be "////",only four slaces not more than four.How should I do that ?

+2  A: 
Regex.Replace(str, @"\s+", "////")
Matthew Flaschen
We don't know whether he wants to replace tabs.
SLaks
+3  A: 

You should use a regular expression:

str = Regex.Replace(str, @" +", "////");
SLaks
@SLaks,Yes I want to replace everything space,tabs which is non-human readeble.
Harikrishna
A: 

You would probably have to convert all double spaces to single in a loop until no more double spaces are left, THEN convert your single space to your "////" instances

DRapp
A: 

Use a regular expression, with the matching pattern being '( )+' (i.e. one or more spaces) and the replacement pattern being the 4 slashes.

Timores