Create a case-insensitive startsWith
PhilipDaniels via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Apr 29 13:03:38 PDT 2015
On Tuesday, 28 April 2015 at 22:34:07 UTC, Justin Whear wrote:
>> if (startsWith!"icmp(a, b) == 0"(input, "0x"))
>> if (startsWith!"std.uni.icmp(a, b) == 0"(input, "0x"))
>> if (startsWith!((a,b) => icmp(a,b) == 0)(input, "0x"))
>
> The issue is that those icmp functions take strings as
> arguments while
> startsWith expects the predicate to take individual characters.
>
Thanks. That seems obvious now that you mention it but honestly I
could not tell that from the documentation :-(
> I believe the best solution here is to use the lazy toLowerCase
> function
> in std.uni and the default predicate:
> if (startsWith(input.toLowerCase, "0x".toLowerCase))
I think I will have to make a "string idioms" wiki page...
More information about the Digitalmars-d-learn
mailing list