我需要在忽略大小写的 D 中比较两个 string
(而不是仅 ASCII)。显然的解决方案是:
s1.toUpper() == s2.toUpper()
但我想避免字符串重复或自己编写一个可能是最快的本地 onde(如果有的话)。
最佳答案
从整整 30 秒开始查找在线 D 引用:
http://dlang.org/phobos/std_string.html
我找到了String.icmp
:
alias icmp = std.uni.icmp(S1, S2)(S1 str1, S2 str2) if (isForwardRange!S1 && is(Unqual!(ElementType!S1) == dchar) && isForwardRange!S2 && is(Unqual!(ElementType!S2) == dchar));
Compares two ranges of characters lexicographically. The comparison is case insensitive. Use std.algorithm.cmp for a case sensitive comparison. For details see std.uni.icmp.
< 0 s1 < s2
= 0 s1 == s2
> 0 s1 > s2
关于string - 如何比较忽略大小写的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25431762/