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:
Any help would be appreciated.
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", "");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.