i have sorted list like this(please refer below code)
code
======
var sd = new SortedList<string, string>();
for (int p = 0; p < yearMatch.Count; p++)
{
sd.Add(YearAdded[p], Id[p]);
}
yearcount = sd.Keys.ToArray();
Id = sd.Values.ToArray();
=========================================
Example
===========
yearcount having year value 2000a,2000b,2000c,20003
Id having value 0020,0025,0030,0035
i want the output like this year value 2000a,b,c,2003
Id value 0020,0025,0030,0035
======================
if same year in the list i want to group that like above i said, i tried in many ways. please any one help guys.its imp and urgent.
Loading
VulpesPosted Jan 31, 2012, 6:23 AM
VulpesPosted Feb 2, 2012, 6:49 AM
However, if you use a MatchEvaluator delegate, like I did in your other thread (http://www.c-sharpcorner.com/Forums/Thread/159829/regular-expression-in-C-Sharp.aspx ), then it's much easier:
Pavi SPosted Feb 1, 2012, 3:53 AM
Some changes in this logic, i want to use regular expression for grouping year
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
string[] yearcount = {"2002a", "2005b", "2002b", "2001"};
string[] Id = {"bb0025", "bb0030", "bb0020", "bb0015"};
var sd = new SortedList
for(int i = 0; i < yearcount.Length; i++)
{
sd.Add(yearcount[i], Id[i]);
}
yearcount = sd.Keys.ToArray();
Id = sd.Values.ToArray();
yearval = Regex.Replace(yearval, @"\b(\d{4})([a-z]),\1([a-z])\b", @"\1\2,\3"); //using like this i want the output like 2001,2002a,b,2005b
Console.ReadKey();
}
}
======================================
i tried the above code it didnt work please help as soon as possible.
Pavi SPosted Jan 31, 2012, 6:36 AM
Pavi SPosted Jan 31, 2012, 5:52 AM
if u give below input it wont work
string[] yearcount = { "2003a", "2005b", "2002b", "2001" };
string[] Id = { "bb0025","bb0030","bb0020","bb0015" };
it will give output like this ly 2001,b,2003a,b
bb0015,bb0020,bb0025,bb0030
but i want the output like this 2001,2002b,2003a,2005b
the logic is if year same that time ly should group the two years
example
=========
2002b,2002a ---->in this condition ly will group like this 2002a,b
2003a,2002b ---->in this condition the year is diffrent so just sort year enough like 2002b,2003a
please help for me for this situation.
VulpesPosted Jan 31, 2012, 4:30 AM