Sumit Prajapati
Sumit Prajapati

Reputation: 91

how to trim text of richtextarea in gwt

I have used "RichTextArea" in GWT. Now i want to trim the text of the richtextarea.gettext() when i am submitting the form.

But if i have only entered spaces and enter key in my textarea then richtextarea.gettext() will not going to trim it as it will convert them to &nbsp and < br>.

Any suggestion if there are only entered spaces and enter key in my textarea then on trim it should give me blank string value?

Upvotes: 0

Views: 1064

Answers (1)

Sam
Sam

Reputation: 2747

That you get &nbsp and < br> is the correct value what you get from the RichTextArea because it supplies HTML.

Implement your own trim-method:

public String trim(String s) {

   String result = s.trim(); 
   String x = result.replaceAll("<br>", "");
   x = x.replaceAll("&nbsp", "");
   x = x.trim();
   if(x.equals("")) {
       return x;
   } else {
       return result;
   }
}

Upvotes: 1

Related Questions