Search code examples
javareplaceapplettextareaspace

Search and Replace All the Searched Text in Java TextArea


I have a Textarea in an applet where the user is supposed to write some text.

I need a code to search what the user wrote and then replace all the spaces "If found" with a "+" sign.

For Example: "Hello World" --> "Hello+World".

My code:

string space = " ";

if textarea.Gettext().contains(space){
space.ReplaceAll("+") }

Solution

  • Use

    string space = " ";
    textarea.setText(textarea.getText().replaceAll(space, "+"));