user826819
user826819

Reputation: 31

java replace special characters to text

I have the following code which is changing the text I am inputting to UPPERCASE

if(WrtMsg.isDisplayable()== true); {
    //System.out.println(test.toString().toUpperCase());
        RecView.setText(test.toString().toUpperCase());
}

Now I want special characters like asterix (*) to be changes as text. Example * to ATX ... So the output will be displayed as ATX.

WrtMsg is the jtextarea of text input and RecView is the jtextarea where the output is showing.

Any help please? Thanks.

Upvotes: 0

Views: 940

Answers (5)

Michell Bak
Michell Bak

Reputation: 13252

Have you considered manually changing it in code? You could create a method like this:

private String charToText(String character) {
character = character.replace("*", "ATX")
// and so forth...
return character;
}

Upvotes: 1

Eng.Fouad
Eng.Fouad

Reputation: 117685

RecView.setText(wrtMsg.getText().replace("*", "ATX"));

Upvotes: 0

Globmont
Globmont

Reputation: 901

if(wrtMsg.getText().contains("*"))
{
    RecView.setText("ATX");
}

Upvotes: 1

Howard
Howard

Reputation: 39217

You should use the replace method of the string object

test.toString().toUpperCase().replace("*", "ATX")

Upvotes: 0

Sanjay T. Sharma
Sanjay T. Sharma

Reputation: 23248

Just use the replaceAll method of the String class. something.replaceAll(Pattern.quote("*"), "ATX").

Upvotes: 1

Related Questions