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

前端 未结 12 622
旧巷少年郎
旧巷少年郎 2020-11-29 03:22

I have a string that contains some text followed by a blank line. What\'s the best way to keep the part with text, but remove the whitespace newline from the end?

12条回答
  •  粉色の甜心
    2020-11-29 03:35

    Another elegant solution.

    String myString = "\nLogbasex\n";
    myString = org.apache.commons.lang3.StringUtils.strip(myString, "\n");
    

提交回复
热议问题