By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

character "grouping" in sort order

P: n/a
In a sorted list, certain characters are grouped together, for example "Áb"
(cedille b) comes after "ca" but before "cc".

Is there a built-in way to find out what 'base character', such as C for
cedille, a character belongs to for a given globalization setting?

Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi

SortedList are sorted by the keys. Also the keys will be sorted by the
coding value of the key character.

Imports System
Imports System.Collections

Module Module1
Sub Main()
' Creates and initializes a new SortedList.
Dim mySL As New System.Collections.SortedList
mySL.Add("ca", "Hello")
mySL.Add("cedille b", "World")
mySL.Add("cc", "!")
For i As Integer = 0 To mySL.Count - 1
Dim str As String = mySL.GetKey(i)
Dim size As Integer =
System.Text.Encoding.Unicode.GetByteCount(str)
Dim buffs(size - 1) As Byte
buffs = System.Text.Encoding.Unicode.GetBytes(str)
For j As Integer = 0 To size - 1
Console.Write("[{0:X}]", buffs(j))
Next
Console.WriteLine()
Console.WriteLine(mySL.GetKey(i) + ": " & mySL.GetByIndex(i))
Next
End Sub
End Module

So I think you may try to print out the keys' coding value to see if there
are any clue.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #2

P: n/a
On Tue, 03 Aug 2004 05:41:22 GMT, v-******@online.microsoft.com ("Peter
Huang") wrote:
Hi

SortedList are sorted by the keys. Also the keys will be sorted by the
coding value of the key character.


Sorry, I should have been more clear, my problem isn't really related to
sorting.

What I'm doing is filling a treeview with a list of names.

The tree has two levels of nodes: the first level contains the letters of
the alphabet, the second contains all names starting with the same letter.
The problem is finding out what first-level node "special" names have to be
placed in, like "«akti" (C) and "÷nder" (O).

In a sorted list they appear at the right place (as if E and … are the same
letter), that's why I referred to it.
So the question is really simple: does a function exist that you can call
to get the "base character" for a certain character, as in

x = MysteriousFunction("…")

which would return "E" in this example.
I might be able to to roll my own, based on System.Globalization.SortKey,
if I knew what the byte values in the KeyData property mean, but that seems
to be undocumented.

It looks like two characters belong to the same base character if the first
two bytes of their sortkeys are the same, so in the worst case I could scan
the alphabet for that condition, if I was certain that there are no
exceptions.

Nov 20 '05 #3

P: n/a
Hi Lucvdv,

Thank you for your input,
Now I am research the issue, and I will update you with new information
ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #4

P: n/a
Hi Lucvdv,

I think so far we do not have such function to do the job. You may try to
build a hashtable to map the special "O" to "O" in your own. So that
everytime you just need to strip off the head letter from the string and
then get their counterpart from the hashtable.

Hope this helps.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #5

P: n/a
On Thu, 05 Aug 2004 02:09:45 GMT, v-******@online.microsoft.com ("Peter
Huang") wrote:
Hi Lucvdv,

I think so far we do not have such function to do the job. You may try to
build a hashtable to map the special "O" to "O" in your own. So that
everytime you just need to strip off the head letter from the string and
then get their counterpart from the hashtable.

Hope this helps.


Thanks.
Just in case someone else is interested, this solution I created yesterday
seems to do the job too (it returns the index of the first-level node the
name goes in, 1-26 for A-Z or 0 for non-alphabetic symbols, using
SortInfo):

Private Function NameRootIndex(ByVal Name As String) As Integer
Static Initialized As Boolean
Static LookupTable(26) As Byte

Dim ch As Char = Name.Substring(0, 1).ToUpper
Dim i As Integer = InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", ch)

If i > 0 Then
Return i
Else
Dim k As Byte
Dim ci As System.Globalization.CompareInfo _
= Application.CurrentCulture.CompareInfo
If Not Initialized Then
For i = 1 To 26
LookupTable(i) = ci.GetSortKey(Chr(64 + i)).KeyData(1)
Next
Initialized = True
End If
With ci.GetSortKey(ch)
If .KeyData(0) <> 14 Then Return 0
k = .KeyData(1)
End With
For i = 1 To 26
If k = LookupTable(i) Then Return i
Next
End If
Return 0
End Function

Nov 20 '05 #6

P: n/a
Hi Lucvdv,

Thank you for you sharing in the community this will help many others.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.