ToCharacterCode["ABCD...XYZ"] - 64 I know that I can make a list of alphabets in this way.
However, I need to assign " " and "." too.
Like " "=27 and "."=28
For example "I AM A BOY." = {9,27,1,13,27,1,27,2,15,25,28}
ToCharacterCode["I AM A BOY."] - 64 /. {-32 -> 32, -18 -> 46} {9, 32, 1, 13, 32, 1, 32, 2, 15, 25, 46}
where " " and "." are mapped to their respective character codes. If you wish to map " " to 27 and "." to 28, you can use
ToCharacterCode["I AM A BOY."] - 64 /. {-32 -> 27, -18 -> 28} {9, 27, 1, 13, 27, 1, 27, 2, 15, 25, 28}
You can do it with PositionIndex and just build the string using CharacterRange:
Catenate@Lookup[ PositionIndex[Characters[CharacterRange["A", "Z"] <> " ."]], Characters["I AM A BOY."]] (* {9, 27, 1, 13, 27, 1, 27, 2, 15, 25, 28} *)
ToCharacterCode["I AM A BOY."] - 64 /. {-32 -> 32, -18 -> 46}? $\endgroup$