Removing white spaces from an ArrayList
-
Hi all I have two problems ist one is that I have stored a string in ArrayList using split function (i.e one word per index). now the problem is that this ArrayList contains white spaces wich is creating problems as well. whereas i have already removed the white spaces from the string :( 2ndly i want to convert an ArrayList into a string. not an array of strings but a single string... looking forward to ur help Regards, -- modified at 13:53 Tuesday 9th May, 2006
-
Hi all I have two problems ist one is that I have stored a string in ArrayList using split function (i.e one word per index). now the problem is that this ArrayList contains white spaces wich is creating problems as well. whereas i have already removed the white spaces from the string :( 2ndly i want to convert an ArrayList into a string. not an array of strings but a single string... looking forward to ur help Regards, -- modified at 13:53 Tuesday 9th May, 2006
friend this may resolve, ur first problem..
private void parseString(String x) { string tempstr; int i=0,len,flag=0; tempstr=""; len=x.Length; while(i < len) { if(x[i]!= ' ') { tempstr = tempstr + x[i]; flag = 0; } else { if(flag == 0) { str.Add(tempstr); tempstr = ""; flag = 1; index++; } } i++; } str.Add(tempstr); }
In this str is arraylist If u have still some doubt, mail me ShivaJee -
Hi all I have two problems ist one is that I have stored a string in ArrayList using split function (i.e one word per index). now the problem is that this ArrayList contains white spaces wich is creating problems as well. whereas i have already removed the white spaces from the string :( 2ndly i want to convert an ArrayList into a string. not an array of strings but a single string... looking forward to ur help Regards, -- modified at 13:53 Tuesday 9th May, 2006
In .NET 2.0 you can use the StringSplitOptions.RemoveEmptyEntries with the String.Split function. Otherwise when you load up your ArrayList just check if the strings contain only white space:
if (myString.Trim()="") // string is nothing but white space so don't add it to your arraylist
To convert back to a string can't you just iterate through the ArrayList and add each entry to a string, or even a StringBuilder? -- modified at 16:53 Tuesday 9th May, 2006 -
Hi all I have two problems ist one is that I have stored a string in ArrayList using split function (i.e one word per index). now the problem is that this ArrayList contains white spaces wich is creating problems as well. whereas i have already removed the white spaces from the string :( 2ndly i want to convert an ArrayList into a string. not an array of strings but a single string... looking forward to ur help Regards, -- modified at 13:53 Tuesday 9th May, 2006
Use foreach to iterate over the array and a stringbuilder and ToString ( if you're not using a string in your foreach ) to pass each object through the stringbuilder to build up your string. Christian Graus - Microsoft MVP - C++