【发布时间】:2014-08-21 16:52:41
【问题描述】:
我需要在 D 忽略大小写的情况下比较两个 strings(而不是仅 ASCII)。显然的解决方案是:
s1.toUpper() == s2.toUpper()
但我想避免字符串重复或自己编写一个支持可能最快的本地 onde(如果有的话)。
【问题讨论】:
标签: string d string-comparison
我需要在 D 忽略大小写的情况下比较两个 strings(而不是仅 ASCII)。显然的解决方案是:
s1.toUpper() == s2.toUpper()
但我想避免字符串重复或自己编写一个支持可能最快的本地 onde(如果有的话)。
【问题讨论】:
标签: string d string-comparison
从 30 秒开始查找在线 D 参考:
http://dlang.org/phobos/std_string.html
我找到String.icmp:
别名 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));
按字典顺序比较两个字符范围。比较不区分大小写。使用 std.algorithm.cmp 进行区分大小写的比较。有关详细信息,请参阅 std.uni.icmp。
< 0 s1 < s2
= 0 s1 == s2
> 0 s1 > s2
【讨论】:
String 类的库参考链接,然后在页面上搜索了“比较”。