如何比较忽略大小写的字符串?

Jac*_*ack 3 string d string-comparison

我需要string在D忽略的情况下比较两个s(而不是仅ASCII).明显的解决方案是:

s1.toUpper() == s2.toUpper()

但是我想避免字符串重复或者自己写一个支持可能最快的原生代(如果有的话).

Law*_*Dol 7

从正好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));

按字典顺序比较两个字符范围.比较不区分大小写.使用std.algorithm.cmp进行区分大小写的比较.有关详细信息,请参阅std.uni.icmp.

< 0     s1 < s2
= 0     s1 == s2
> 0     s1 > s2
Run Code Online (Sandbox Code Playgroud)

  • 也许我的眼睛太累了.:( (2认同)