c# - split array and get last value of each index -
i have string looks
string sortorder= "download-15104,download-15103,download-15105,download-15106,download-15107,download-16104,download-16105";
and want ids . , did
var ids= new list<int>(); var sortorderarray = sortorder.split(','); foreach (var item in sortorderarray) { var obj = item.split('-'); ids.add(int.parse(obj[1])); }
is there other way , quick ?
you use linq:
var ids = input.split(',').select(x => int.parse(x.split('0')[1])).tolist();
but, it not faster. uses loops internally anyway. may more readable.
Comments
Post a Comment