char 的增量

Incrementation of char(char 的增量)
本文介绍了char 的增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些问题,询问如何让 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 列.显然只是增加一个 char 不会这样做 - 它会转到 '['.

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 '['.

或者,即使在单个字符内,有效值的范围也可能是不连续的——最明显的例子是十六进制.如果你增加 '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".

这篇关于char 的增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)