Reputation: 251
I have an array of string . I want to remove an item from string. HOw i can do this.
string []values = User.Split(';');
Suppose values contains "1","2","3","4"
I want to delete or remove item "2" from values. How i can do this. Is there built in function in C#
Upvotes: 2
Views: 32120
Reputation: 24923
Array is immutable object. So, you can't remove from array. You can create new array without this value using LINQ:
values = values.Where(o=> o != "2").ToArray();
Or, you can create List and remove from list:
List<string> values = User.Split(';').ToList();
values.Remove("2");
Upvotes: 9