How to map character to numeric position in java?

前端 未结 7 1976
忘了有多久
忘了有多久 2020-11-30 06:26

E.g.

  • input: [\'A\', \'Z\', \'F\', \'D\', ...]
  • output: [0, 25, 5, 3, ...]

In C I\'d just subtract the char from \'A\', but I don\'t seem

7条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 06:37

    The output you are expecting is just the offset of a upper case letter with respect to 'A'. So just subtract the Unicode value of 'A' from the unicode value of the letter whose offset is needed.

    example: 'B' - 'A' = 1

提交回复
热议问题