焦炭增量 [英] Incrementation of char
问题描述
我发现了一些问题,询问如何让字符'B'返回'C',然后'D'等答案是相当复杂,大多只是矫枉过正。
I found some question asking how to let char 'B' to return 'C' and then 'D' etc. The answers were quite complex and mostly just overkill.
为什么不能简单地使用这样的:
Why not to use simply this:
char X='A';
X++
编辑:它从A到Z和下一步是什么?
It goes from A to Z and what next?
推荐答案
如果您满意,让结果,那么这很好。
If you're happy with the results that gives, then that's fine.
一般情况下,他们希望从Z到AA或类似的东西来包装,虽然 - 像Excel列。显然只是递增一个字符不会这么做的 - 它会去[
Usually when I've seen questions like that, they want to wrap from "Z" to "AA" or something like that that though - like Excel columns. Clearly just incrementing a char won't do that - it would go to '['.
另外,即使在单个字符,有效的值的范围可能是非-contiguous - 明显的例子是十六进制。如果你增加'9'你':'而不是'A'或'A',你可能想要的。所需的顺序是很少无论Unicode的给你。
Alternatively, even within a single character, the range of valid values may be non-contiguous - the obvious example being hex. If you increment '9' you get ':' instead of the 'a' or 'A' which you probably wanted. The desired order is rarely "whatever Unicode gives you".
这篇关于焦炭增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!