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.
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:
You could define a function like:
This could either be implemented use a dictionary:
or use switch as you mentioned:
Now the function is ready, you could just iterate through your string and call transform against each characters.
Following pieces of code are based on the ASCII representation of the letters.
From char array:
Take care of the case sensitivity. The code above works for upper case only, as 65 is the ASCII code for 'A' (not 'a').
Don't try the switch statement, it'll look horrible.
EDIT: If you really want the switch statement, here it is:
To get the final