How to arrange my Quater data ascending way without using Regex

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
i have data stored in List<String> and data look like a which stored in list

1Q 2014A

2Q 2014A

2012FY

1Q 2013A

2Q 2013A

4Q 2014A

4Q 2013A

2013 FYA

2011FY

3Q 2014A

3Q 2013A

2010FY

2014 FYA

i need to order or arrange data in list like below way. the order is small year comes first

and then order quarter like 1Q 2010A, 2Q 2010A, 3Q 2010A,4Q 2010A, 2010 FYA. this way i need to order whole data.

sample order data as follows


2010FY

2011FY

2012FY

1Q 2013A

2Q 2013A

3Q 2013A

4Q 2013A

2013 FYA

1Q 2014A

2Q 2014A

3Q 2014A

4Q 2014A

2014 FYA
tell me with minimum code how could i order data like above without regex? provide some sample code.

i got to order with regex like below code but i need to do it without regex

var list = new List<String>
{
"1Q 2014A",
"2Q 2014A",
"2012FY",
"1Q 2013A",
"2Q 2013A",
"4Q 2014A",
"4Q 2013A",
"2013 FYA",
"2011FY",
"3Q 2014A",
"3Q 2013A",
"2013FY",
"2010FY",
"2014 FYA",
};

var result =
list
.OrderBy( s => Regex.Match( s, @"\d\d\d\d" ).Value )
.ThenBy( s => Regex.Match( s, @"^.Q" ).Value + '5' )
.ThenBy( s => !Regex.Match( s, @"FYA$" ).Success )
.ThenBy( s => !Regex.Match( s, @"FY$" ).Success )
.ToList( );



thanks

Continue reading...
 
Back
Top