Convert a word into character array

后端 未结 5 1705
花落未央
花落未央 2021-01-19 07:16

How do I convert a word into a character array?

Lets say i have the word \"Pneumonoultramicroscopicsilicovolcanoconiosis\" yes this is a word ! I would like to take

5条回答
  •  梦毁少年i
    2021-01-19 07:49

    You can use the Linq Aggregate function to do this:

    "wordsto".ToLower().Aggregate(0, (running, c) => running + c - 97);
    

    (This particular example assumes you want to treat upper- and lower-case identically.)

    The subtraction of 97 translates the ASCII value of the letters such that 'a' is zero. (Obviously subtract 96 if you want 'a' to be 1.)

提交回复
热议问题