Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Linq order list by substring

$
0
0

I have list of strings like:
AB1DF|Mango
A2kdF|Strawberry2
IDLWI22|GRAPE
SI|lemon1
LIN|watermelon
SKI|lemon2
BDW04|Strawberry1

Each string is made of 2 substrings separated by pipeline (|)
For a given input string, I have to create sublist where the substring from '|' is like the given input string,
and I am doing this as:

IEnumerable<string> result = JobsList.Where(
    delegate(string s) { return s.Substring(s.LastIndexOf("|")).ToLower().Contains(strInput.ToLower());});

and the above works good.

Now I want the above result list be in the order of substrings after the pipeline character.
For example, if the input string is 'strawberry' the result should be:
BDW04|Strawberry1
A2kdF|Strawberry2

and not in the reverse order

How do I add OrderBy clause to the above linq to order by substring following the '|' character?

Thanks,

-srinivas y.


sri


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>