如何按字母顺序找出下一个字符? [英] How to find out next character alphabetically?

查看:15
本文介绍了如何按字母顺序找出下一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何找出输入字符的下一个字符.例如,如果我输入了字符b",那么如何得到答案c"?

How we can find out the next character of the entered one. For example, if I entered the character "b" then how do I get the answer "c"?

推荐答案

试试这个:

char letter = 'c';

if (letter == 'z')
    nextChar = 'a';
else if (letter == 'Z')
    nextChar = 'A';

else
    nextChar = (char)(((int)letter) + 1);

这样,当字符是字母表的最后一个时,您就不会遇到麻烦.

This way you have no trouble when the char is the last of the alphabet.

这篇关于如何按字母顺序找出下一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆