How to convert an alphanumeric phone number to digits

前端 未结 7 965
臣服心动
臣服心动 2021-01-05 12:50

UPDATE:

The final version of my utility looks like this:

StringBuilder b = new StringBuilder();

for(char c : inLetters.toLowerCase(         


        
7条回答
  •  独厮守ぢ
    2021-01-05 13:23

    You could do this using the Apache Commons Lang StringUtils, as follows:

    String output = StringUtils.replaceChars(StringUtils.lowerCase(input),
                        "abcdefghijklmnopqrstuvwxyz",
                        "22233344455566677778889999");
    

    Assuming speed is not your main concern, of course, and you want a compact solution ;)

提交回复
热议问题