如何从字符串的开头和结尾删除换行符(Java)?

问题描述:

我有一个字符串,其中包含一些文本,后跟一个空白行.保留文本内容并从末尾删除空白换行符的最佳方法是什么?

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?

使用

Use String.trim() method to get rid of whitespaces (spaces, new lines etc.) from the beginning and end of the string.

String trimmedString = myString.trim();