Re: c++ string to lowercase


[ Follow Ups ] [ Post Followup ] [ CS1044 Web Discussion Board ] [ FAQ ]

Posted by William D McQuain on December 04, 2001 at 11:54:39:

In Reply to: c++ string to lowercase posted by Shawn Pullum on December 04, 2001 at 00:39:53:

: hi everyone, i was wondering if anyone knew an easy way to convert a string (c++ style) to lowercase and/or uppercase. i am hoping there is a simple built in function where i don't have to use char arrays. thanks.

There are standard library functions for changing case, tolower() and toupper(). You can also access the elements of a string as if it was an array:


#include
#include
using namespace std;

int main() {

string Place = "Blacksburg, VA";

cout << Place << endl;

for (int Idx = 0; Idx < Place.length(); Idx++) {
Place[Idx] = tolower(Place[Idx]);
}

cout << Place << endl;

return 0;
}




Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS1044 Web Discussion Board ] [ FAQ ]