How do I compare strings ignoring the case?

I need to compare two string

(not just ASCII) in case of ignoring D. Obviously the solution is:

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

But I want to avoid duplicate lines or write myself in favor of the fastest onde possible (if any).

+3


source to share


1 answer


Search D online help with an accuracy of 30 seconds at:

http://dlang.org/phobos/std_string.html

I found 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 case comparison. See the std.uni.icmp file for details.

< 0     s1 < s2
= 0     s1 == s2
> 0     s1 > s2

      

+7


source







All Articles