[solved. thank you!] upper case
-
how do you know if a word (QString) begins with an upper case letter and how to make this first letter to be upper?
-
via Qt Centre forum (I not checked this)
@QString capitalize(const QString &str)
{
QString tmp = str;
// if you want to ensure all other letters are lowercase:
tmp = tmp.toLower();
tmp[0] = str[0].toUpper();
return tmp;
}@ -
<nitpick>
Actually that code is not correct since Unicode does have funny little chars like "01C9;LATIN SMALL LETTER LJ". That is one lowercase letter (lj).Uppercasing that gives you "01C7;LATIN CAPITAL LETTER LJ" (LJ).
So that is not what you want.
You want "01C8;LATIN CAPITAL LETTER L WITH SMALL LETTER J" (Lj), which is the Titlecase. So you should use toTitleCase() instead of toUpper().
</nitpick> -
i solved with
@
QString parola = "ciao";
parola.replace(0, 1, parola[0].toUpper());
//returns Ciao
@ -
@
QString parola = QLatin1String("ciao");
parola[0] = parola.at(0).toTitleCase();
@ -
right! ;)