Reputation: 1059
I have a list as given below.
List<string> testing = new List<string>();
testing.Add("1(1)(r)");
testing.Add("2(4)");
testing.Add("3(w)");
testing.Add("33(4)");
testing.Add("5(4)");
testing.Add("6(6)");
Now my problem is that i want to remove full string on or after "(" my list should be something like as given below.
1
2
3
33
5
6
How can i solve this problem with lambda expression or is ther any other way to remove string after some specific character. Thanks in advance
Upvotes: 0
Views: 44
Reputation: 101681
var result = testing.Select(x => x.Split('(')[0]);
Another way:
var result = testing.Select(x => x.Substring(0, x.IndexOf('(')));
Second approach will throw exception if one of your strings doesn't contain any (
Upvotes: 1