counting characters
celavek via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 19 05:20:31 PDT 2016
On Tuesday, 19 July 2016 at 09:55:43 UTC, Jonathan M Davis wrote:
> On Tuesday, July 19, 2016 09:41:32 John via Digitalmars-d-learn
> wrote:
>
> auto result = count(dna_chain, 'A');
>
> or if you know that the string is always going to just contain
> ASCII (as seems likely based on the example), then
> string.representation can be used to convert the string to
> immutable(ubyte)[] in order to avoid the auto-decoding that
> occurs with string and range-based functions. e.g.
>
> auto result = count(dna_chain.representation, 'A');
>
> That's almost certainly the fastest way to do it with Phobos.
>
> - Jonathan M Davis
Thank you. I used what you suggested as I have only ASCII
characters.
More information about the Digitalmars-d-learn
mailing list