Sorting - Sort List(of String()) Using A Variable Index Into String() As Key ?

May 30, 2012

I have a List(of String()). I have written a custom comparer (implements IComparer(of string)) to do an alphanumeric sort.Is there a way to sort the List using a given index to determine which position in the String() to sort by? In other words one time I might sort by Index = 0 and another time by Index = 3. The length of all String() in the list is the same.For reference this question is similar to Sort List<String[]> except I am using VB.net and that question is hardwired to Index=0.

EDIT from OP's comments:I started simple with the non custom comparer but I am getting an error: expression does not produce a value. Not sure what I am doing wrong.Here is the code:

Public Shared Function SortListOfStringArray(ByVal ListOfStringArray As List(Of String()), ByVal SortByIndex As Integer) As List(Of String())
Return ListOfStringArray.Sort(Function(x, y) x(SortByIndex).CompareTo(y(SortByIndex)))
End Function

View 1 Replies


ADVERTISEMENT

Sorting List Of String Paths In .NET?

Aug 14, 2010

I would like to sort a list of strings which represent paths. The sort result will do have a hierarchical order. What I mean is: for each directory path, I want to list all files in that path (alphabeticaly or not doesn't matter) in first time. Then, each subdirectory path will be listed. For each subdirectory, I want all files..

[Code]...

View 2 Replies

Sort A List (Of String) Alphanumerically?

Apr 26, 2012

I have looked, unsuccessfully, for how to sort a list of strings alpha numerically. The .Sort() method sorts it like so:

abc,abc1,abc11,abc12,abc2,abc21,abc22

I don't want it sorted that way, I want it sorted like so:

abc,abc1,abc2,abc11,abc12,abc21,abc22

View 1 Replies

Alphabetically Sort A Generic List (Of String) In .NET?

Dec 1, 2009

I've created and populated a generic list of strings like this:

Dim MyList As New List(Of String)
MyList.Add("Beta")
MyList.Add("Echo")

[code]....

Now I want to order it.

View 1 Replies

Find Index In List(of String)

Jun 7, 2010

I have an List(of String), i need to find the index of a particular string in that list. I have searched msdn , but i am confused over the predicate methods. I have never used predicates. This i what i have tried

vb
'on button1 click
Dim Heads As List(Of String) = Me.GetSelectedNodes()
Dim tmp As Integer

[Code].....

View 1 Replies

How To Search List By Index Or String

Aug 29, 2011

How on specific behaviour can be created in a custom class. I want to be able to create a custom class (a kind of list) where I can access the items by their index (this is the easy part), but also by a string that would describe them. Here is an example:
MyClass(1).SomeProperty = "NewValue"
MyClass("Item1").SomeProperty = "NewValue"

You can see this kind of behaviour in dataset for example where you can select a table by its name or by its index like this :
DataSet.Tables("MyTable").Rows...
DataSet.Tables(1).Rows...
How can I create a custom class that will behave like this?

View 2 Replies

.net - Function To Accept List(Of String), Array & String And Similarly Return List(Of String)?

Jul 29, 2011

I want the Function to accept List(Of String), Array & String and similarly return List(Of String), Array & String respectively. The Function simply adds a string (month) to the input collection. I just want to use it for string, array and list with needing to think of conversions.

[Code]...

View 2 Replies

Sorting - List.sort Not Working?

Apr 3, 2009

I have a slightly odd problem that I think is most likely due to an act of foolishness on my part, but for the life of me I (and other members of my team) can't see it.I have an object that contains a generic list property which I would like to sort. I have written a comparer class to do this for me and I am calling it in the following way:baseObject.ListOfThings.Sort(new ThingComparer()I have debugged into my compare function and it is returning the right values.However After the sort call, the list remains unchanged. Have I missed something obvious, or is there something else I need to do.EDIT: Yes I was being a fool, and the property returning a list was recreating it from scratch each time it was accessed

View 4 Replies

Sorting List (Of Structure) - Sort Multiple Variables

Feb 17, 2011

I'm using a Listview in VirtualMode, so I can 'add' a lot of files almost instantly. A Listview in VirtualMode does not allow sorting, so I need to sort the data myself. The data is stored as a List of Structure (it's faster to load than a List of ListViewItem). The code below works fine, but I need to sort based on multiple variables in the Structure. Code:

View 2 Replies

Search A String Variable And Place The Match Into Another String Variable In Visual Basic?

Nov 18, 2009

I'm looking for a way to search a string variable for two words and copy the text in between them into another variable. This needs to be done as many times as the match occurs.

View 3 Replies

Sort ListView By Image.Index If Index Over 4 Sort Rest Alphabetically

Apr 12, 2012

Currently my ListView sorts items by image.index. So 0 is at the top, then 1, 2 and so on. Think of it as an IRC chat room nick list. Ops at top then the rest are sorted alphabetically

[Code]....

View 18 Replies

VS 2010 How To 'sort' A List Variable

Feb 19, 2011

I have this

Public strDBData As New List(Of SearchDatabases)
Public Structure SearchDatabases
Public strName as String

[code].....

If you need to know what i'm doing this it it:I'm parsing a webpage that lists information such as; Name, Site URL, How many members etc.And thats fine, but i want to put the names in a listbox, and then when the user clicks a name in the listbox it displays the other data about that name such as the site URL and how many members they have.This is easy to do but i have made my listbox sorted so the names display alphabetically, so then my strDBData index's don't line up correctly, to fix this i need to sort the

View 6 Replies

Split Comma Separated String In Text File And Save Each String In Different Variable?

Dec 5, 2011

These is the content of my txt file which is saved in D drive in my pc abc,1,2,3..I tried the flowing but it didn't work:[code]I am getting error on this line.. data = line.Split(","c)...it says this line isn't in use anymore or something and that I rather use LineInput but thats asks for filenumber and i don't know what that is. I am sorry but I am a complete beginner. what else can I try? [code]ok that error is gone now but now if I want to add these values to a list box..how can i do that?

View 1 Replies

Module Level Variable - Array And Sort List

Mar 13, 2009

I just need to know where my code is jacked -up at, I get an error when I created the module level variable ( class statement must end with a matching end class) problem is that every time I add an end class the next procedure is wrong with the same error, so what can I do to resolve this and why is this error coming up. Ultimate goal of this program is to add the invoice totals to the next element in the array each time the user clicks calculate, which displays in a message when the user clicks the exit button, also this code will sort the invoice totals in the array.

Public Class frmInvoiceTotal
Dim SumInvoice(4) As Decimal 'Delareation of two module- level variables
Dim I As Integer = 0' the index I can use to work with this array
Private Sub btnCalculate_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnCalculate.Click
[Code] .....

View 3 Replies

C# - With LINQ, How To Transfer A List<List<string>> To List<string>

Dec 15, 2010

I got an object of List<List<string>>I need to bring this into a ist<string>I have no idea how to do this with LINQ.

View 1 Replies

When String Variable Was Empty String First One Returns 'nothing'

Oct 2, 2009

just found out that replace(string does not do the same as string.replace when my string variable was an empty str the first one returns "nothing" and the second returns an empty string (as expected).just sloppy coding anyhow, it was a function that was converted from classic asp and never rewritten properly. [code]

View 1 Replies

Convert List Of String To A String Separated By A Delimiter

Apr 15, 2009

Whats the best way to convert a list(of string) to a string with the values seperated by ,

View 3 Replies

Array.Sort(array) - Specify A Numeral Sort Based On The First Character In The String?

Jan 29, 2009

Sub Sort()
ReDim RollsCC(NumOfPlayers - 1)
For N As Integer = 0 To (NumOfPlayers - 1)[code]....

Here I am creating a temp single dimensional array, merging my 2d array into it, and then attempting to sort it by Rolls(N,1), which is a integer 1-6, Everything seems to be working right with the exception of this.

RollsCC.Sort(RollsCC, 0, 1)

How would one specify a numeral sort based on the first character in the string? im aware that I am switching Rolls(n,1) and Rolls(n,0) information during the sort.

View 5 Replies

Combining A String And String Variable Into One Variable

Apr 4, 2009

I am trying to insert a string variable inside of two strings, and make a combined string. Public Sub Page_Load() Dim Id As String Id = Trim (Request.QueryString("Id")) End Sub Dim mp3text as string url... & Id & ".mp3" My goal is to make the mp3text variable have a string that is: url...(If Id is 7) It is for some reason not connecting up correctly. I checked what string it is outputting and this is what it is giving: url...It is missing the Id content.

View 12 Replies

Can't Load A String Into A String Variable?

Apr 12, 2009

I am using the MODI DLL (Microsoft Office Document Imaging) because it has an OCR engine. That's working fine, but I'm having trouble capturing the resulting text into my own string variable (weird, huh). Modi has the result stored in the following Modi string variable:

img.Layout.Text

I've tried three ways to capture this value, only one of them works (not the one that I need to work)

(1) Dim txt as string = img.Layout.Text 'fails

(2) MsgBox(img.Layout.Text) 'fails

(3) M = new Msg(img.Layout.Text) 'succeeds

Method 3 (the only one working) is a custom msgbox I built in VB.Net, and it accepts a regular .Net string variable. I need Method-1 to work. The error thrown is this:

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt." I even tried it like this:

(1) Dim txt as string = img.Layout.Text.ToString.Trim

Here's the complete code:

Dim doc As New MODI.Document
doc.Create("C:VCR.tif")
Dim img As MODI.Image

[Code].....

View 4 Replies

Replace All String In String Variable?

Apr 18, 2011

how can I replace all string in string variable like

dim str = "I am testing and testing and testing"
After replace with "and"
ReplaceAll(str,"and","or")

How can I replace all with case insentive not case sensative?

View 3 Replies

Sorting A String Array With Numbers?

Feb 12, 2010

Lets say I have the following String Array:

Code:
dim strArr(3) as String
strArr(0) = "15 Joseph"
strArr(1) = "24 Nick"
strArr(2) = "3 Mike"

[Code]...

View 2 Replies

Sorting/Splitting String In ArrayList?

Aug 20, 2010

Basically, Im running an SQL query to the database, which obviously returns data in their fields. What I want to do is add each record into an ArrayList and split the string based on fields. I.E

CustomerID,Surname,GivenName etc

How do I go about this? so far I have:

alstData.AddRange(sLine.Split(","c))
sLine = the record from the database.

This doesnt seem to work, it just display's the data in one line with no split such as 20205SmithJohn?

View 8 Replies

VS 2010 - String Sorting In Order Numerically

May 3, 2012

I have a list of strings lets say the items are like this:
item_1
item_2
item_4
item_10
item_8
item_11

If I do list.sort() I get the following
item_1
item_10
item_11
item_2
item_4
item_8
Somehow I need to get these in order numerically but I am dealing with strings not numbers.

View 7 Replies

.net - How To Sort A Observablecollection(of String)

May 21, 2012

All I need is a simple way to sort the strings in the collection. I can't find anything online. Everybody is using lamda expressions which I don't think works for just a string collection?

Public Property FilterCollection As New ObservableCollection(Of String)

From d In FilterCollection Order By (Function(d) d)()

View 1 Replies

Sort String With Number?

Mar 22, 2012

I'm coding my project that need to make string become number based from alphabet position example : "work" become "4231" because in "work" string "k" is the small alphabet than the others and "w" is the biggest now I wanna make 2 textbox, the first textbox is a place I put "work" then after I press a button the second textbox show a result "4231" is it possible to do ?

I already try to use array.sort but I don't know how to give a position after I sort it or maybe there is other way to sort it ?

View 6 Replies

Convert A List(of String) To String()?

Nov 11, 2011

Dim namelist As List(Of String) = New List(Of String)
namelist.Add("Hi")
namelist.Add("Hello")

[code].....

View 4 Replies

How To Declare List(Of String()) With String(2)

May 5, 2012

I am trying to declare List(Of String(2)) and it doesn't work

I understood that if I specify the length of the string() the compiler will not need to guess the length and it will be more fast that way, is it correct?

View 3 Replies

List(of String) To Dim Item()() As String

Oct 22, 2011

I have a list with a few items ( changes once in a while ) named itemlist

[Code]...

View 9 Replies

VS 2010 Sorting String In Ascending/descending Order?

Jun 1, 2011

I am performing some filescans in a directory where I always neither get ascending or descending order of filenames. What I currently have is a logical order, but what I want to make of it is an ascending order.

[Code]...

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved