Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compare strings ignoring case?

I need to compare two strings (and not ASCII-only) in D ignoring case. The obviously solution is:

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

But I want to avoid strings duplications or write one myself in favor of a possibily fastest native onde (if any).

like image 1000
Jack Avatar asked Mar 29 '26 21:03

Jack


1 Answers

From exactly 30 seconds looking up the online D reference 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 a case sensitive comparison. For details see std.uni.icmp.

< 0     s1 < s2
= 0     s1 == s2
> 0     s1 > s2
like image 127
Lawrence Dol Avatar answered Apr 02 '26 21:04

Lawrence Dol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!