# how to concatenate the values

Posted by Murugavelmsc under C# on 2/28/2013 | Points: 10 | Views : 1203 | Status : [Member] | Replies : 10
Hi Experts,

Input:

10, 12, 3, 23, 6, 7, 9, 1, 11, 8

output
1, 3, 6-7, 8-12, 23

Thanks,
Murugavel S

Regards,
Murugavel S
http://murugavelmsc.blogspot.in/

#### Responses

Posted by: Jayakumars on: 2/28/2013 [Member] [MVP] Bronze | Points: 25
Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25
 0 Hi, order the given number in ascending .... Regards, Murugavel SRegards, Murugavel S murugavel.sadagopan@gmail.com http://murugavelmsc.blogspot.in/Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Vuyiswamb on: 2/28/2013 [Member] [MVP] [Administrator] NotApplicable | Points: 25
Posted by: Somu475 on: 2/28/2013 [Member] Starter | Points: 25
 0 Hi Murugavelmsc, Please elaborate your logic. If you want to arrange the given numbers in ascending order then what is this series 1, 3, 6-7, 8-12, 23 ...?? -SomuMurugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25
 0 Hi Somu, sort the given as ascending as follows: 1, 3, 6, 7, 8, 9, 10, 11, 12, 23 then check the two numbers ..... 1, no consective numbers, 3, no consectives number, 6,7,8,9,10,11,12 consective numbers so replace as 6-12, and 23.... I hope u are clear now.... Thanks, Murugavel S Regards, Murugavel S murugavel.sadagopan@gmail.com http://murugavelmsc.blogspot.in/Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Raja_89 on: 2/28/2013 [Member] Starter | Points: 25
 0 Hai int [] i = new int [10] {25,78,1,78,69,410,782,84,46,6} ; Array.Sort(i); foreach (int print in i) { Console.Write (print +"\n " ); } Regards Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25
 0 Hi All I got it.... Console.WriteLine("Enter input values seperated by comma"); string val = Console.ReadLine(); ArrayList inputval = new ArrayList(); // Split the input values and stored in arraylist ArrayList spltval = new ArrayList(val.Split(',')); int i = 0; // Convert the splitval to integer and stored in arraylist for (i = 0; i < spltval.Count; i++) inputval.Add(Convert.ToInt32(spltval[i])); // Sort the arraylist inputval.Sort(); Console.WriteLine("Input values after sorting"); Console.WriteLine("**************************"); for (i = 0; i < inputval.Count; i++) Console.WriteLine(inputval[i]); Console.WriteLine("Ouput values"); Console.WriteLine("************"); // Method call to Get the series result GetResult(inputval, 0); Console.ReadKey(); } static private void GetResult(ArrayList arrval, int index) { // start value of the series int startval = Convert.ToInt32(arrval[index]); // end value of the series int endval = Convert.ToInt32(arrval[arrval.Count - 1]); int series = startval; int i; // Check the series for (i = index; i < arrval.Count; i++) { int cmpval1 = int.Parse(arrval[i].ToString()); int cmpval2 = series++; //+i; if (cmpval1 != cmpval2) { endval = int.Parse(arrval[i - 1].ToString()); break; } } index = i; // print result Console.WriteLine(startval + "-" + endval); // Recurssion - Call if the arraylist is completed or not if (i < arrval.Count - 1) GetResult(arrval, index); return; } Thanks, Murugavel S Regards, Murugavel S murugavel.sadagopan@gmail.com http://murugavelmsc.blogspot.in/Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Mutturaj on: 2/28/2013 [Member] Starter | Points: 25
 0 Hi, I understood your logic like that only, but in original post you have mentioned 1, 3, 6-7, 8-12, 23 instead of 1, 3, 6-12, 23. I think everyone got confused because of that. So plz post properly from next time.Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25