- Code: Select all
void toUpper(string &str)
{
for (unsigned int i = 0; str[i] != '\0'; ++i)
{
if (str[i] > 0x60 && str[i] < 0x7b)
str[i] &= 0xdf;
}
}
void toLower(string &str)
{
for (unsigned int i = 0; str[i] != '\0'; ++i)
{
if (str[i] > 0x40 && str[i] < 0x5b)
str[i] |= 0x20;
}
}
Using by reference is the preferred way, but you can use pointers to if you have to.
- Code: Select all
void toUpper(string *str)
{
for (unsigned int i = 0; str->operator[](i) != '\0'; ++i)
{
if (str->operator[](i) > 0x60 && str->operator[](i) < 0x7b)
str->operator[](i) &= 0xdf;
}
}
void toLower(string *str)
{
for (unsigned int i = 0; str->operator[](i) != '\0'; ++i)
{
if (str->operator[](i) > 0x40 && str->operator[](i) < 0x5b)
str->operator[](i) |= 0x20;
}
}
