I am trying to replace a character '.' in my a string with "[.]", using .replace function as you can see in the code below. However, the string doesn't go beyond 16 characters. On the other hand, by using .insert function, there is no limit for the length of the string. Is there any explanation for this behavior? Thanks
I used .insert function instead.
newString = "255.100.50.0";
int len = newString.length(), i =0;
while(i < len){if(newString[i] == '.'){
newString.replace(i,1, "[.]");
len = newString.length();
}
i += 3;
}
cout << newString << endl;
Aucun commentaire:
Enregistrer un commentaire