0

Hello:

I am developing a web app using Java and beans.

I am trying to do a converter which checks if a message which the user introduces using a textarea is less than 5 characters long.

The difficulty is that event if the text area is empty it stills having /r/n and some spaces after it.

I have alreaady tried:

@Stateless
public class ComentarioNota {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    public String convierteComentarioNota(String evaluacion, String comentario) {
        if (evaluacion.trim().equals("Apto") && comentario != null && comentario.length() > 5) {
            return "Apto";
        } else {
            return "No Apto";
        }
    }
}

And when debbugging we can see the comment value in the comentario parameter:

enter image description here

Any help would be appreciated.

Yone
  • 2,064
  • 5
  • 25
  • 56

1 Answers1

1

You can remove the linebreaks before the trim. How to remove line breaks from a file in Java?

How to remove newlines from beginning and end of a string (Java)?

text = text.replace("\n", "").replace("\r", "");
Richard Stiller
  • 143
  • 1
  • 10