1

I have a string "abc defg h"

I wanted to translate each letter into the corresponding number for example 'A' as '00', 'B' as '01'

eg

'hello' --> '06 04 10 10 14'

ps would a dictionary help at all with this?

Thanks in advance

Joel Coehoorn
  • 380,066
  • 110
  • 546
  • 781
K_McCormic
  • 324
  • 1
  • 5
  • 17

1 Answers1

5

You examples do not match up. Should H be 6 or 7? This is a basic example, but it only handles letters well, spaces and punctuation you will have to determine how you want to handle:

    Dim value As String = "HELLO"
    For Each character In value.ToUpper()
        Debug.Print((Asc(character) - 65).ToString("00"))
    Next
John Koerner
  • 36,569
  • 8
  • 80
  • 129
  • If instead of hardcoding Asc('A') as 65 you use `Asc(character) - Asc('A')`, then your only assumption is that the alphabetic characters are consecutive. – AAT Feb 07 '12 at 12:43