如何从字符串的开头和结尾删除换行符? [英] How to remove newlines from beginning and end of a string?

查看:414
本文介绍了如何从字符串的开头和结尾删除换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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();

这篇关于如何从字符串的开头和结尾删除换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆