Question

I want to store large strings converted to decimals in a SortedDictionary (as the key) but they must fit a certain format...Due to the nature of sorting strings, they will not be placed correctly as a decimal would. Here are some examples:

Public dic_Extracted As New Dictionary(Of Decimal, clsBillExtract)    

'Display the keys and their index in the dictionary (as string and as decimal)
"000000000000000000000000000" 'String Index = 0, Decimal Index = 0
"001000000000000000000000000" 'String Index = 1, Decimal Index = 1
"002000000000000000000000000" 'String Index = 3, Decimal Index = 2
"010000000000000000000000000" 'String Index = 2, Decimal Index = 3

When the keys are placed in the dictionary as decimals, the preceding zeros will be trimmed ... Like so:

String: "001000000000000000000000000" will be the key 1000000000000000000000000...

Is there a way to keep the preceding zeros?

Was it helpful?

Solution

To keep the order you want, have Decimals as keys and format them to Strings when needed (on-the-fly).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top