Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the last new line (\n)

Tags:

java

I have the code below. the if condition is true and it goes into the line inside the IF but when I inspect answerText later, it still has the new line at the end

if(answerText.endsWith("\n")){
     answerText = answerText.substring(0, answerText.length()-2);           
}
like image 209
code511788465541441 Avatar asked Dec 21 '13 17:12

code511788465541441


1 Answers

answerText = answerText.trim()

public String trim()

Returns a copy of the string, with leading and trailing whitespace omitted.

like image 140
Adam Siemion Avatar answered Oct 04 '22 08:10

Adam Siemion