/    Sign up×
Community /Pin to ProfileBookmark

StringBuffer replace

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 !

to post a comment
Java

2 Comments(s)

Copy linkTweet thisAlerts:
@buntineJan 14.2005 — 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.
Copy linkTweet thisAlerts:
@rafisoauthorJan 14.2005 — ha ok , thanks you.

.replace() replace chars and not substrings ? thx
×

Success!

Help @rafiso spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...