What's Here?
- Members: 244,060
- Replies: 692,832
- Topics: 113,100
- Snippets: 3,863
- Tutorials: 935
- Total Online: 1,409
- Members: 90
- Guests: 1,319
|
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: 67,634 |
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
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|