Convert the words into numbers on the keypad.

topic description

convert words to numbers on the keypad.
such as "dell" converted to 335.5. "alienware" converted to 254369273

sources of topics and their own ideas

use JavaScript function to write, considering that if you want to use switch, you can output 2 with [a-cA-C], but it is not clear how to write it. Solve

Mar.15,2022

it's easy to swap numbers with letters. A mapping table is fine, but do you want to map aquarz directly with 0such 9 ? I admire your brain circuits

< hr >
const DATA = [
  '',
  '',
  'abcABC',
  'defDEF',
  'ghiGHI',
  'jklJKL',
  'mnoMNO',
  'pqrsPQRS',
  'tuvTUV',
  'wxyzWXYZ',
];

const getNumber = str => str.split('').map(v => DATA.findIndex(s => s.includes(v))).join('');

this is the 9-grid conversion method written earlier, refer to

getNumber('r')// 7
getNumber('d') //3

java programming converts 26 letters into 09digits in the form of a mobile phone keyboard

this seems to match your needs


you can try to use the ASCII code to judge, but it feels that the array method above is actually more efficient

public static String getNum(String value)
    {
        StringBuffer sbu = new StringBuffer();
        char[] chars = value.toCharArray();
        for (int i = 0; i < chars.length; iPP) {
            int num = (int)chars[i];

            if (num < 97 || num >122){
                return "";
            }
            int index = (num -97)/3;
            if (index < 5) {
                sbu.append(index+2);
            }else if(num < 116){
                sbu.append(7);
            }else if(num < 119){
                sbu.append(8);
            }else{
                sbu.append(9);
            }


        }
        return sbu.toString();
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e56446-43e77.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e56446-43e77.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?