Using .find and .replace with strings
Ok here is my homework assignment... I have it working for some instances but not for others.
Here is the code that does the conversion..
Essentially i have a string like... C++ is awesome!
it must convert C++ to java.
then it converts all letters to Uppercase
I have it working with there is one instance of C++, however if there is none or more than one it will not work proper. Im figured i need to do some kind of loop that goes through checking for C++ and changing it if it finds it .... not sure how exactly to do that
Code:
modified = original;
pos = original.find("C++");
modified.replace(pos,3,"java");
upperStr = modified;
int i = 0;
while (i<modified.length())
{
if (modified[i] == ' ' || modified[i] == ',' || modified[i] == '.')
{
upperStr[i] = modified[i];
}
if (modified[i] >= 65 && modified[i] <= 90)
{
upperStr[i] = modified[i] + 32;
}
if (modified[i] >= 97 && modified[i] <= 122)
{
upperStr[i] = modified[i] - 32;
}
i++;
}