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

BoQsc vaidas.boqsc at gmail.com
Mon Jul 5 19:19:19 UTC 2021


On Monday, 5 July 2021 at 18:59:09 UTC, jfondren wrote:
> On Monday, 5 July 2021 at 18:53:27 UTC, jfondren wrote:
>>
>> If you replace the findAmong call with 
>> `[letter].findAmong(alphabet)`, this works.
>
> Consider:
>
> ```d
> import std;
>
> void main() {
>     import std.ascii : alphabet = letters;
>
>     string wordExample = "Book.";
>     foreach (letter; wordExample) {
>         writefln!"%c is %sa letter"(letter, 
> [letter].findAmong(alphabet).length ? "" : "not ");
>         writefln!"%c is %sa letter"(letter, 
> alphabet.canFind(letter) ? "" : "not ");
>     }
>     writeln("___>>___finally some letters".findAmong(alphabet));
> }
> ```

If I use `[letter].findAmong(alphabet)` in my code, it considers 
a dot (.) punctuation character as a letter.
You can see it here:
https://run.dlang.io/is/YWmaXU



More information about the Digitalmars-d-learn mailing list