Click to See Complete Forum and Search --> : StringBuffer replace


rafiso
01-14-2005, 05:46 AM
Hello,

I'm doing a very easy script on a jsp page, but it seems to be looping for ever.

while (myStringBuffer.length() > 100) {
myStringBuffer.replace(0, myStringBuffer.indexOf(">") , "test");
}

and of course after 2 or 3 replacements "myStringBuffer.length()" is smaller than 100..

Do you have any idea ?

Thx !

buntine
01-14-2005, 07:54 AM
But your replacing one character with four. So the string will only get larger.

You could use: while (myStringBuffer.length() < 110)

Or you could use an incrementing variable. eg while (i < 4)

Regards.

rafiso
01-14-2005, 07:58 AM
ha ok , thanks you.

.replace() replace chars and not substrings :) thx