c# extracting words -
i have following piece of code me iam spliting words using 1 space , output
output:
when ambition ends happiness begins
but want split words after 2 spaces mean output should this:
when ambition ends happiness begins
string vj = "when ambiton ends happiness begins"; list<string> k = new list<string>(); char ch = ' '; string[] arr = vj.split(ch); foreach (string r in arr) { response.write(r + "<br/>"); }
string vj = "when ambiton ends happiness begins"; list<string> k = new list<string>(); char ch = ' '; string[] arr = vj.split(ch); bool flag=false; foreach (string r in arr) { if(flag) { response.write(r + "<br/>"); flag=false; } else { response.write(r + " "); flag=true; } }
the above case specified (skipping single space).
though not necessary, if want wrapped up, here :
string mystring = "when ambiton ends happiness begins"; bool flag=false; foreach (string item in mystring.split(ch)) response.write(item + flag=!flag?" ":"<br/>");
Comments
Post a Comment