如何自动删除所有空格开始或结束的字符串 [英] How automatically remove all white spaces start or end in a string

查看:202
本文介绍了如何自动删除所有空格开始或结束的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何自动删除在这样一个字符串中的所有空格开头或结尾:

How automatically remove all white space start or end in a string like:

你好收益你好结果
你好收益你好结果
你好收益你好结果
的Hello World收益的Hello World

"hello" return "hello"
"hello " return "hello"
" hello " return "hello"
" hello world " return "hello world"

关于

推荐答案

字符串.Trim() 将削减所有的的空格,从开始 的一个字符串的结尾:

String.Trim() will trim all white-spaces from start and end of a string:

"   A String   ".Trim() -> "A String"

String.TrimStart()将削减所有的空格从字符串的开头:

String.TrimStart() will trim all white-spaces from the start of a string:

"   A String   ".TrimStart() -> "A String   "

String.TrimEnd()将削减所有的空格从字符串的结尾:

String.TrimEnd() will trim all white-spaces from the end of a string:

"   A String   ".TrimEnd() -> "   A String"

这篇关于如何自动删除所有空格开始或结束的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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