Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
I'm trying to sort some strings in order by number, I've tried a sorted listbox and even using the sort method with an array. I have three lists of strings and combine them into a sorted listbox. The beginning of the string starts with a number in this format ( of string), but the numbers don't sort properly as 20 will become before 120 because it starts with 20. I want the biggest number first downwards. Hope I explained this right as it's a pretty weird problem.
Thanks for any help
Posted 30-Mar-13 18:37pm
Sergey Alexandrovich Kryukov at 30-Mar-13 23:58pm
This is simple, but... how come you got such list in first place?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Don't use just Sort, use Sort(Comparison):[^].
I hope, you can find the comparison criterion: extract the number, use int.Parse (or some other appropriate "Parse") to find the number, compare numbers, not strings.
However, first of all, think how could you end up having strings with numbers, instead of a list or other collection with properly structured data. This is one of the worst beginner's trends these days: using strings representing data instead of data itself. Get rid of the bad habits.
Kieran Crown at 31-Mar-13 0:16am
I'm basically downloading the data from a MySQL database. I need the name of the data (string) Nd to sort them strings by a number (popularity). I'm making my own custom auto suggest feature and need to sort the results. Thanks
Sergey Alexandrovich Kryukov at 31-Mar-13 0:18am
Do you see that I answered your question in full? Use the said Sort method.
Kieran Crown at 31-Mar-13 0:46am
Yes I did but you also asked me why I needed such a list so I was just answering that.
Sergey Alexandrovich Kryukov at 31-Mar-13 1:05am
Sure, I understand that... Thank you for answering.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web04 | 2.8.150326.1 | Last Updated 30 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100