Java: How to replace a word in a string with another word?

Av
6

I'm currently programming a Minecraft plug-in, where I have the one arbitrary string in which the word PLAYER occurs. I would like to replace the PLAYER with the player name. I just can't find a solution to replace the word.

Am still quite a beginner, so synonymous with a small explanation to the source code.

Av

BTW, It is a simple JoinListener where the join message is read from the Config.

pe

System.out.println ("my name is" + name + "and I'm playing Minecraft.");

Av

Rather a method to remove a word from a string, replace it with another string and then cancel the finished string.

Di

You can do that with the method

String # replace (target, replacement)

do. You can find more on https://docs.oracle.com/...rSequence) :)

Av

Thanks for the quick reply, works great.

Di

Nice that I could help you!