Hi all,
First post here!
And I have registered because I have literally spent the last 6 hours searching High & Low, all over this site, every search term I could think of, and all over google, to find this answer to No avail.
I need to capitalize the first letter of every word in a string, without using any loops in the capitalization process.
Specifically I am going to use this to retrieve the strings, stored in an array, and lowercase every letter in each string, then uppercase the first letter of every word.
I am currently using standard library functions (?) to take care of the lowercasing without using any loops, but cannot figure out how to capitalize the first letter in every word thereafter without using loops.
Here's what I have so far for lowercasing:
1 2 3 4
|
string s=*whatever goes here*;
int (*tl)(int) = tolower; // Selecting this particular overload
transform(s.begin(),s.end(),s.begin(),tl );
|
and this is what I have for uppercasing Every letter in the string, after they have all been lowercased:
1 2 3
|
int (*tu)(int) = toupper;
transform(str.begin(), str.end(), str.begin(), tu));
cout << str << std::endl;
|
My
main issue is, telling a function to uppercase Only the first letter of every word in a string (that contains a sentence).
Maybe something from the string member function can be used?
Or something with c-string, buffer, fill, or range for a string? I don't really know what those are (I'm a programming n00b in my first class), but they seem like they may allow for differentiating between areas in a string.
Maybe using string::find_first_of, string::find, or string::replace functions?