Search code examples
flutterdartascii

How to convert a character to integer ascii number in dart (flutter)?


I want to convert a character to that ascii number for example convert Z => 90.

I know the inverse of that but I can't find this. Exactly I want to shift entered value to two char upper.

For example I want to convert A to C or B to D or Y to A

Sorry I can't write English well


Solution

  • as far as i understand here is the code:

    String shiftChar(String character) {
      int charCode = character.codeUnitAt(0);
      if (charCode >= 65 && charCode <= 90) {
        return String.fromCharCode(((charCode - 65 + 2) % 26) + 65);
      } else if (charCode >= 97 && charCode <= 122) {
        return String.fromCharCode(((charCode - 97 + 2) % 26) + 97);
      } else {
        return character;
      }
    }