Given a string such as "abcdefghijklmnopqrstuvwxyz"
, how would I go about returning a list of the alphabetical number of each letter in the string, example being 1,2,3,4,5,6,7,8,9
etc.?
2
$\begingroup$
$\endgroup$
4
$\begingroup$
$\endgroup$
1 - First@ToCharacterCode@"a" + ToCharacterCode@"abcdefghijklmnopqrstuvwxyz"
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}
2
$\begingroup$
$\endgroup$
str = "abcdefghijklmnopqrstuvwxyz"
p = StringPartition[str, 1]
{"a", "b", "c", etc.}
ord = Rule @@@ Transpose @ {Alphabet[], Range[Length@Alphabet[]]}
{"a" -> 1, "b" -> 2, "c" -> 3, etc.}
p /. rule
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}