From: intruder83-help on 6 Mar 2010 05:35 Hi everybody. I have a problem with sorting an array of names. I have a txt file with a names e.g. "Jack, John, Bob, Adam, Paul". All i have to do is write the names into the individual cells of new array and than sort it by an alphabet using for loop and write it out into a new txt file. I just after figuring out how to separete a names and my source code looks like: string delimiter = ","; string path = @"c:\notsorted.txt"; string r = sr.ReadLine(); string[] names = r.Split(delimiter.ToCharArray()); but i have no idea how to sort it with for loop. If there is anyone who can help me it would be great! Thanks
From: Alberto Poblacion on 6 Mar 2010 05:42 "intruder83-help" <intruder83-help(a)discussions.microsoft.com> wrote in message news:2F82D017-1985-40CA-B871-20355E7DD139(a)microsoft.com... > but i have no idea how to sort it with for loop. > If there is anyone who can help me it would be great! First of all you have to choose a sorting algorithm. There are plenty of them; for instance, you can find the description for Bubble Sort in this page: http://en.wikipedia.org/wiki/Bubblesort . The wikipedia article contains some sample code in various programming languages. Follow the links at the bottom of the page for other sorting algorithms.
From: Patrice on 6 Mar 2010 07:16 It is already part of the Array class : http://msdn.microsoft.com/en-us/library/system.array.sort(VS.80).aspx -- Patrice "intruder83-help" <intruder83-help(a)discussions.microsoft.com> a écrit dans le message de news:2F82D017-1985-40CA-B871-20355E7DD139(a)microsoft.com... > Hi everybody. > I have a problem with sorting an array of names. I have a txt file with a > names e.g. "Jack, John, Bob, Adam, Paul". > All i have to do is write the names into the individual cells of new array > and than sort it by an alphabet using for loop and write it out into a new > txt file. > I just after figuring out how to separete a names and my source code looks > like: > > string delimiter = ","; > string path = @"c:\notsorted.txt"; > string r = sr.ReadLine(); > string[] names = r.Split(delimiter.ToCharArray()); > > but i have no idea how to sort it with for loop. > If there is anyone who can help me it would be great! > Thanks
From: Family Tree Mike on 6 Mar 2010 07:34 On 3/6/2010 5:35 AM, intruder83-help wrote: > Hi everybody. > I have a problem with sorting an array of names. I have a txt file with a > names e.g. "Jack, John, Bob, Adam, Paul". > All i have to do is write the names into the individual cells of new array > and than sort it by an alphabet using for loop and write it out into a new > txt file. > I just after figuring out how to separete a names and my source code looks > like: > > string delimiter = ","; > string path = @"c:\notsorted.txt"; > string r = sr.ReadLine(); > string[] names = r.Split(delimiter.ToCharArray()); > > but i have no idea how to sort it with for loop. > If there is anyone who can help me it would be great! > Thanks Why not use a list instead? List<string> names = r.Split(delimiter.ToCharArray()).ToList(); names.Sort(); -- Mike
|
Pages: 1 Prev: Save changes for a custom configuration section Next: C# working with reporting services |