-2

Possible Duplicate:
Convert first letter in string to uppercase

How do I convert a string to title case in C++ "hello world" to "Hello World" . The string can even have multibyte characters

Community
  • 1
  • 1
user1065276
  • 287
  • 1
  • 3
  • 6
  • 1
    Are you looking for a library function or are you asking for a description of an algorithm that does so? – André Caron Dec 16 '11 at 06:47
  • Since you mentioned multi-byte, I've retagged this as [tag:wstring]. If this is incorrect, you can change it back, and be more specific as to what you are using. (Give an example.) – Mateen Ulhaq Dec 16 '11 at 06:58

1 Answers1

1

Well, if you follow the advice on your previous question, Convert first letter in string to uppercase, all you need to do is split the string into one word each, and uppercase it.

std::wstring s = L"iron maiden";

if(s.length() > 0)
    s[0] = toupper(s[0]);

for(std::wstring::iterator it = s.begin() + 1; it != s.end(); ++it)
{
    if(!isalpha(*(it - 1)) &&
       islower(*it))
    {
        *it = toupper(*it);
    }
}

Basically, you just have to write/use a parser.

Community
  • 1
  • 1
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135