|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
sort two arrays as one?arrword() as string arrnumber() as integer How can I best sort both arrays together using the integer array as the column to sort by in descending numerical order? This is what I want to achieve: 1 alive 1 beginning 1 covered 4 along 6 all 13 of 17 earth 62 and I tried putting the two arrays into a third single column string array and used array.sort(ThirdArray) but got these not so good results. This does not achieve my numberical sort requirement This is not what I want: 1 alive 1 beginning 1 covered 13 of 17 earth 4 along 6 all 62 and On Nov 27, 11:38 am, BobAchgill <BobAchg***@discussions.microsoft.com>
wrote: Show quoteHide quote > I have 2 arrays with identical number or rows. What is the relationship between the two arrays?> > arrword() as string > arrnumber() as integer > > How can I best sort both arrays together using the integer array as the > column to sort by in descending numerical order? > > This is what I want to achieve: > 1 alive > 1 beginning > 1 covered > 4 along > 6 all > 13 of > 17 earth > 62 and > -- Tom Shelton one to one
e.g. There is 1 "alive" word There are 17 "earth" words There are 62 "and" words These represent statistics of how many times these words occur in a portion of text. I just want to sort the data into a list of most occuring to least occuring words based on the word count column. Each word has one associated word count number in the other array. Show quoteHide quote "Tom Shelton" wrote: > On Nov 27, 11:38 am, BobAchgill <BobAchg***@discussions.microsoft.com> > wrote: > > I have 2 arrays with identical number or rows. > > > > arrword() as string > > arrnumber() as integer > > > > How can I best sort both arrays together using the integer array as the > > column to sort by in descending numerical order? > > > > This is what I want to achieve: > > 1 alive > > 1 beginning > > 1 covered > > 4 along > > 6 all > > 13 of > > 17 earth > > 62 and > > > > What is the relationship between the two arrays? > > -- > Tom Shelton > On Nov 27, 12:28 pm, BobAchgill <BobAchg***@discussions.microsoft.com>
wrote: > one to one Ok... so they have cooresponding indexes... they are parrallel> > e.g. > > There is 1 "alive" word > There are 17 "earth" words > There are 62 "and" words > > These represent statistics of how many times these words occur in a portion > of text. I just want to sort the data into a list of most occuring to least > occuring words based on the word count column. Each word has one associated > word count number in the other array. > arrays. Ok, that makes some sense. now i can think on a solution :) -- Tom Shelton BobAchgill,
You can sort 2 parallel arrays with Array.Sort, like this: Array.Sort(arrnumber, arrword) However, for words associated with the same number, this won't sort in ascending order by word. So you might get this: 1 covered 1 beginning 1 alive 4 along 6 all 13 of 17 earth 62 and Kerry Moorman Show quoteHide quote "BobAchgill" wrote: > I have 2 arrays with identical number or rows. > > arrword() as string > arrnumber() as integer > > How can I best sort both arrays together using the integer array as the > column to sort by in descending numerical order? > > > This is what I want to achieve: > 1 alive > 1 beginning > 1 covered > 4 along > 6 all > 13 of > 17 earth > 62 and > > I tried putting the two arrays into a third single column string array and > used array.sort(ThirdArray) but got these not so good results. This does not > achieve my numberical sort requirement > > This is not what I want: > 1 alive > 1 beginning > 1 covered > 13 of > 17 earth > 4 along > 6 all > 62 and > > On Nov 27, 2:39 pm, Kerry Moorman
<KerryMoor***@discussions.microsoft.com> wrote: Show quoteHide quote > BobAchgill, Funny... I never noticed that array.sort allowed that. Well, you> > You can sort 2 parallel arrays with Array.Sort, like this: > > Array.Sort(arrnumber, arrword) > > However, for words associated with the same number, this won't sort in > ascending order by word. So you might get this: > > 1 covered > 1 beginning > 1 alive > 4 along > 6 all > 13 of > 17 earth > 62 and > > Kerry Moorman > > > > "BobAchgill" wrote: > > I have 2 arrays with identical number or rows. > > > arrword() as string > > arrnumber() as integer > > > How can I best sort both arrays together using the integer array as the > > column to sort by in descending numerical order? > > > This is what I want to achieve: > > 1 alive > > 1 beginning > > 1 covered > > 4 along > > 6 all > > 13 of > > 17 earth > > 62 and > > > I tried putting the two arrays into a third single column string array and > > used array.sort(ThirdArray) but got these not so good results. This does not > > achieve my numberical sort requirement > > > This is not what I want: > > 1 alive > > 1 beginning > > 1 covered > > 13 of > > 17 earth > > 4 along > > 6 all > > 62 and- Hide quoted text - > > - Show quoted text - learn something new every day. -- Tom Shelton Tom Shelton wrote:
> Yes, I only discovered this recently myself while trying to find a way > Funny... I never noticed that array.sort allowed that. Well, you > learn something new every day. > to sort Structures based on any Member of the Structure. I found it very difficult to find a solution, so if anyone else is looking for the same I'd be happy to provide the code. Maybe the OP would be interested in merging his two (or more) arrays into a Structure Array? ShaneO There are 10 kinds of people - Those who understand Binary and those who don't. You could build yourself a 2 column DataTable...
Dim dt As New DataTable dt.Columns.Add(New DataColumn("TheCount", Type.GetType("System.Int32"))) dt.Columns.Add(New DataColumn("TheWord", Type.GetType("System.String"))) .... Load the rows, .... and then sort... dt.DefaultView.Sort = "TheCount, TheWord" -- Show quoteHide quoteTerry "BobAchgill" wrote: > I have 2 arrays with identical number or rows. > > arrword() as string > arrnumber() as integer > > How can I best sort both arrays together using the integer array as the > column to sort by in descending numerical order? > > > This is what I want to achieve: > 1 alive > 1 beginning > 1 covered > 4 along > 6 all > 13 of > 17 earth > 62 and > > I tried putting the two arrays into a third single column string array and > used array.sort(ThirdArray) but got these not so good results. This does not > achieve my numberical sort requirement > > This is not what I want: > 1 alive > 1 beginning > 1 covered > 13 of > 17 earth > 4 along > 6 all > 62 and > >
Copying files with progress bar
How to stop disabled text boxes being greyed out VB2008 changes? Call HTML control in code behind (ASP.net 2.0) Visual Studio 2005: VB fill circle automatic Can I write this program? Setting up Policies to run Exe file from network drive Kill explorer process and disable it restart automatically Problem Using VB.net Class Library DLL in VBScript using foxpro table from VB.net 2005 with oledb |
|||||||||||||||||||||||