8
Well, it depends what exactly you want to do with the "edge cases". What result do you expect when the character is z or Z? Do you want the next letter of the same case, or just the next letter, period?
這取決於你要怎么處理“邊緣情況”。當字符是z或z時,您期望得到什么結果?你想要同樣情況下的下一個字母,還是下一個字母,句號?
Without knowing the answer to that, for the very basic case, you can just do this:
在不知道答案的情況下,對於最基本的情況,你可以這樣做:
$next_character = chr(ord($current_character) + 1);
But when you're at Z this will give you [, and z will give you {, according to ASCII values.
但是當你在Z時,它會給你[,Z會根據ASCII值給你{。
Edited as per comment:
編輯/評論:
If you need the next character of the same case, you can probably just add simple checks after the line above:
如果您需要相同情況下的下一個字符,您可以在上面的行后添加簡單的檢查:
if ($next_character == '[')
$next_character = 'A';
else if ($next_character == '{')
$next_character = 'a';
These are very simple operations, I really wouldn't worry about efficiency in a case like this.
這些都是非常簡單的操作,在這種情況下我真的不會擔心效率。