vendredi 16 mars 2018

Java, how could we trim carriage return and line break?

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.

Aucun commentaire:

Enregistrer un commentaire