What's Here?
- Members: 300,288
- Replies: 825,450
- Topics: 137,350
- Snippets: 4,417
- Tutorials: 1,147
- Total Online: 2,076
- Members: 124
- Guests: 1,952
|
Two functions, used to convert c++ strings from upper case to lowercase and vice versa. Each takes a string argument, and returns the converted string. Please note that parameters should be validated before passing them to the functions.
|
Submitted By: Amadeus
|
|
Rating:
 
|
|
Views: 75,690 |
Language: C++
|
|
Last Modified: February 25, 2005 |
|
Instructions: Include either the ctype.h OR cctype libraries, as well as the stdlib.h as part of the preprocessor directives. |
Snippet
string StringToUpper(string strToConvert)
{//change each element of the string to upper case
for(unsigned int i=0;i<strToConvert.length();i++)
{
strToConvert[i] = toupper(strToConvert[i]);
}
return strToConvert;//return the converted string
}
string StringToLower(string strToConvert)
{//change each element of the string to lower case
for(unsigned int i=0;i<strToConvert.length();i++)
{
strToConvert[i] = tolower(strToConvert[i]);
}
return strToConvert;//return the converted string
}
Copy & Paste
|
|
|
|