I want to remove all '\0' characters from the items of an ArrayList in c#. Here is my code:
ArrayList users = um.getAllUsers(server,Instance); //user count=3
So now I want to add a code in order to replase all '\0' with empty string in all the items of the list.
Is this possible?
First, it's a little odd to still be using ArrayList in 2010... and also to have Camel cased names (getAllUsers rather than GetAllUsers) but still...
for (int i = 0; i < users.Count; i++)
{
string user = (string) users[i];
user = user.Replace("\0", "");
users[i] = user;
}
If you're not stuck with some ancient version of .NET, you might be interested in upgrading your code to use the generic List<T> collection and have a look at LINQ:
List<string> users = um.getAllUsers(server,Instance)
.Cast<string>()
.Select(user => user.Replace("\0", ""))
.ToList();
(I assume getAllUsers returns an ArrayList containing string instances).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With