I have a listbox in which there are columns for Street and Street Numbers. Street Numbers are string type that can be in various formats:
No. 1
No. 11-13
No. 118, 120, 122
No. 62a-64b
the problem is when doing a sort in Street Numbers, 11 or 110 comes before 2 or 20 as the first character 1 in ascii goes before 2, how can I resolve this?
Find a database that does natural sort like Valentina.
The following code is the comparator for sorting text which has numbers at the end like “account-1” and “account-2” and so on:
[code]Public Function Compare(s1 as String, s2 as String) as Integer
// Part of the StringComparator interface.
const NSCaseInsensitiveSearch = 1
dim theRegex as new RegEx
theRegex.searchPattern = “(.*)(\d)+”
'if one of the search texts doesn’t contain a number it doesn’t matter
dim theRegexMatch as RegExMatch = theRegex.search(s1)
if theRegexMatch = nil then
Return NSStringCompareMBS(s1, s2, NSCaseInsensitiveSearch)
else
s1 = theRegexMatch.subExpressionString(1) + Right(“00000” + theRegexMatch.subExpressionString(2), 5)
end if
theRegexMatch = theRegex.search(s2)
if theRegexMatch = nil then
Return NSStringCompareMBS(s1, s2, NSCaseInsensitiveSearch)
else
s2 = theRegexMatch.subExpressionString(1) + Right(“00000” + theRegexMatch.subExpressionString(2), 5)
end if
Return NSStringCompareMBS(s1, s2, NSCaseInsensitiveSearch)
End Function
[/code]
I would dump the addresses into an in-memory SQLite database with an extra field containing the VAL() of the address, then SELECT the address back again, but ORDER BY valueField.