Results 1 to 10 of 10

Thread: How to capitalize a string

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to capitalize a string

    There's no function to change the first character of a string to upper case because such a function makes little sense in many languages; it is a task specific mainly to Western languages and alphabets. In today's global, Unicode world the majority of readers would find such a function useless.

    If that's all you need, however, however, myString[0].toUpper() will get you there. Feel free to define a macro, or a function, or simply hard-code the solution wherever it's needed.

  2. #2
    Join Date
    Nov 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to capitalize a string

    You can use QFont::setCapitalization(). I guess the rationale is that it's a rendering step.

    Reid

  3. #3
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to capitalize a string

    Hi,

    I guess you want to capitalize all nouns in a sentence, as is common for titles in English.

    Use the split method of QString, using a space as separator. This gives you a list of strings. toUpper() each first character of each string in the stringlist. Then concatenate all the strings back together, putting a space in between them.

    You could add exceptions that the words 'and' and 'or' and such are not capitalized.

    Best regards,
    Marc

Similar Threads

  1. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 08:51
  2. Int to String - manipulating string
    By mickey in forum General Programming
    Replies: 6
    Last Post: 5th November 2007, 20:11
  3. Problem with std::string's
    By Rayven in forum General Programming
    Replies: 1
    Last Post: 17th July 2007, 18:29
  4. how to get a part of the string
    By probine in forum Newbie
    Replies: 2
    Last Post: 4th December 2006, 14:37
  5. String value
    By Gayathri in forum Newbie
    Replies: 2
    Last Post: 21st November 2006, 05:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.