September 13, 2011

spode spode
Lab Rat
317 posts

[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?

5 replies

September 13, 2011

Vass Vass
Ant Farmer
740 posts

via Qt Centre forum (I not checked this)

  1. QString capitalize(const QString &str)
  2. {
  3.      QString tmp = str;
  4.      // if you want to ensure all other letters are lowercase:
  5.      tmp = tmp.toLower();
  6.      tmp[0] = str[0].toUpper();
  7.      return tmp;
  8. }

 Signature 


Vasiliy

September 13, 2011

Tobias Hunger Tobias Hunger
Area 51 Engineer
3383 posts

<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>

September 13, 2011

spode spode
Lab Rat
317 posts

i solved with

  1. QString parola = "ciao";
  2.     parola.replace(0, 1, parola[0].toUpper());
  3. //returns Ciao

September 13, 2011

Tobias Hunger Tobias Hunger
Area 51 Engineer
3383 posts

  1. QString parola = QLatin1String("ciao");
  2. parola[0] = parola.at(0).toTitleCase();

September 13, 2011

spode spode
Lab Rat
317 posts

right! ;)

 
  ‹‹ QT 4.7.4 SDK 1.1.3 error : QColor::setNamedColor: Unknown color name ’...’      Item3D / mesh : restore original effect after it has been altered? ››

You must log in to post a reply. Not a member yet? Register here!