Find a char among string (string.findAmong.char)

BoQsc vaidas.boqsc at gmail.com
Tue Jul 6 11:35:14 UTC 2021


On Monday, 5 July 2021 at 19:48:13 UTC, jfondren wrote:
> On Monday, 5 July 2021 at 19:34:14 UTC, BoQsc wrote:
>>
>> But I really don't like how it looks less readable and makes 
>> less sense on first look.
>> `if (([letter].findAmong(alphabet)).length)`
>> I'd like to use some method on the `letter` instead of []
>> And `.length` does not make a lot of sense when reading like 
>> an english sentence.
>
> I suggest canFind, like in my earlier example. findAmong is 
> like "consume this range until you find one of these things, 
> and then return the remainder of the range". It doesn't really 
> fit your use.

I tried out .canFind method, and to test it I removed the letter 
'o' from the Alphabet.
Weirdly enough .canFind method still found 'o' letter among the 
Alphabet.

https://run.dlang.io/is/2Fvenf



More information about the Digitalmars-d-learn mailing list