Reputation: 27
I've got a list of strings called xyz the string has this structure iii//abcd, iii//efg. how can I loop through this list and remove only iii// ? I have tried this but it remove everything. thanks
string mystring = "iii//";
xyz.RemoveAll(x=> x.Split ('//')[0].ToString().Equals (mystring));
Upvotes: 0
Views: 2653
Reputation: 16878
I believe OP wants something to remove iii//
from all strings:
string prefix = "iii///";
List<string> xyz = ...;
var result = xyz.Select(x => x.Substring(prefix.Length)).ToList();
Note: this of course assumes that each string really starts with prefix
.
Upvotes: 0
Reputation: 853
You can try this also which will remove the string from list if it starts with "iii/" other wise not.
string mystring = "iii//";
xyz.RemoveAll(x=>x.StartsWith(mystring));
Upvotes: 0
Reputation: 29836
Removing all the strings who start with iii//
:
xyz.RemoveAll(x => x.StartsWith(@"iii//"));
Removing the iii//
from all strings:
var newList = xyz.Select(x => x.Replace(@"iii//", string.Empty)).ToList();
Upvotes: 5