c# - Cut last character from string which was earlier splitted by char -


i want order list string names name included in brackes.

list<string> result = new list<string>();             list.foreach(elem => result.add(elem.value));             result.add(item);             result = result.orderby(o=>o.split(';')[0].substring(0, o.length - 1).split('(')[1]).tolist(); 

example: 2-osobowy(agrawka);Śniadanie+obiadokolacja want extract name agrawka how change instruction substring(0, o.length - 1)to cut last char splitted string in orderby instruction?

if right understood want extract values in brackets , sort input' list values. code below sorts data , extracts value additional list:

        list<string> resultlist = new list<string>() { "2-osobowy(bgrawka);Śniadanie+obiadokolacja", "2-osobowy(agrawka);Śniadanie+obiadokolacja" };         string tempstr = null;         var extractedstr = new list<string>();         resultlist = resultlist.orderby(o =>         {             var extract = (tempstr = o.split(';')[0].split('(')[1]).substring(0, tempstr.length - 1);             extractedstr.add(extract);             return extract;         }).tolist(); 

if want sort input data simplify lambda:

        resultlist = resultlist.orderby(o => (tempstr = o.split(';')[0].split('(')[1]).substring(0, tempstr.length - 1)).tolist(); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -