0

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?

Alex
  • 4,821
  • 16
  • 65
  • 106
  • A decimal is a number, the display format has no relevance. If you want to keep the zero then store strings not decimals – Steve May 06 '13 at 13:03
  • @Steve Strings are sorted differently than decimals so I can't put strings. I showed the difference of their indexes as strings and as decimals in the code snipet – Alex May 06 '13 at 13:11
  • 2
    @Alex: Then have Decimals as keys and format them to Strings when needed (on-the-fly). – Victor Zakharov May 06 '13 at 14:24
  • @Neolisk Yeah ... I think that's what I'll do. You can post it as an answer and I'll go ahead and accept it :p – Alex May 06 '13 at 14:28

1 Answers1

1

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

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151