Difference between toLower() and asLowerCase() for strings?

Jon D via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 24 13:19:25 PST 2016


On Sunday, 24 January 2016 at 21:04:46 UTC, Adam D. Ruppe wrote:
> On Sunday, 24 January 2016 at 20:56:20 UTC, Jon D wrote:
>> I'm trying to identify the preferred ways to lower case a 
>> string. In std.uni there are two functions that return the 
>> lower case form of a string: toLower() and asLowerCase(). 
>> There is also toLowerInPlace().
>
> toLower will allocate a new string, leaving the original 
> untouched.
>
> toLowerInPlace will modify the existing string.
>
> asLowerCase will returned the modified data as you iterate over 
> it, but will not actually allocate the new string.
>
> [snip...]
>
> As a general rule, the asLowerCase (etc.) version should be 
> your first go since it is the most efficient. But the others 
> are around for convenience in cases where you need a new string 
> built anyway.

Great explanation, thank you!


More information about the Digitalmars-d-learn mailing list