lower case only first letter of word
Mengu
mengukagan at gmail.com
Tue Dec 5 14:34:57 UTC 2017
On Tuesday, 5 December 2017 at 14:01:35 UTC, Marc wrote:
> On Tuesday, 5 December 2017 at 13:40:08 UTC, Daniel Kozak wrote:
>> but this will change all other uppercase to lowercase, so
>> maybe it is not what you want. If you really want just change
>> first char to upper, then there is nothing wrong to do it
>> yourself
>>
>> On Tue, Dec 5, 2017 at 2:37 PM, Daniel Kozak
>> <kozzi11 at gmail.com> wrote:
>>
>>> Something like this:
>>> https://dlang.org/phobos/std_uni.html#asCapitalized
>>>
>>> On Tue, Dec 5, 2017 at 2:31 PM, Marc via Digitalmars-d-learn
>>> < digitalmars-d-learn at puremagic.com> wrote:
>>>
>>>> Does D have a native function to capitalize only the first
>>>> letter of the word? (I'm asking that so I might avoid
>>>> reinvent the wheel, which I did sometimes in D)
>
> Yes, this is not what I want. I want to convert only the first
> letter of the word to lower case and left all the others
> immutable. similar to PHP's lcfirst():
>
> http://php.net/manual/en/function.lcfirst.php
this is how i'd do it:
string upcaseFirst(string wut) {
import std.ascii : toUpper;
import std.array : appender;
auto s = appender!string;
s ~= wut[0].toUpper;
s ~= wut[1..$];
return s.data;
}
More information about the Digitalmars-d-learn
mailing list