i want to change chars with numbers, for example: a with 1, b with 2… z with 26. so the string “hello” will be something like this: 82491513621. the first question is: how to do this with easiest way, and the second: how to do this with SWITCH statement. i tried this, but after break; it stops. thanks.
Share
You need a loop, whatever you do. A simple switch is not enough.
Some explanation: since all letters have a numeric ASCII code associated in alphabetic order, it means that from any char representing a letter we can subtract ‘a’ and add 1 to get its numeric rank in the alphabet.
If using the switch statement is an absolute requirement, you will need to write a separate case for each possible value of a character: