How to get the next letter of the alphabet in Javascript?

后端 未结 7 1054
醉酒成梦
醉酒成梦 2021-01-03 18:20

I am build an autocomplete that searches off of a CouchDB View.

I need to be able to take the final character of the input string, and replace the last character wit

7条回答
  •  感动是毒
    2021-01-03 18:51

    // This will return A for Z and a for z.

    function nextLetter(s){
        return s.replace(/([a-zA-Z])[^a-zA-Z]*$/, function(a){
            var c= a.charCodeAt(0);
            switch(c){
                case 90: return 'A';
                case 122: return 'a';
                default: return String.fromCharCode(++c);
            }
        });
    }
    

提交回复
热议问题