在c#win中删除字符串右侧的空格。形成 [英] Remove white space from right side of string in c# win. form

查看:99
本文介绍了在c#win中删除字符串右侧的空格。形成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#win中从字符串右侧删除空格。表格?

示例: -

How can i remove white space from right side of string in c# win. form?
Example:-

Hello__World_____//Here "_" means a blank



输出


OUTPUT

Hello__World



注意: - Hello 世界之间的空格应保持 2 并且我的文字大于 Theseus 所以不建议迭代或循环



直到现在我可以只需写一下


Note:- Between Hello and World white space should remain 2 and my text is bigger than a Theseus so don't suggest iteration or looping.

Till now i could just write

string s = "Hello  World     ";
s = s.Trim();



但这消除了你好和世界之间的差距





提前致谢


But this removes gap between hello and world


Thanks in advance

推荐答案

尝试
string s = "Hello  World     ";
s = s.TrimEnd();




Agent_Spock写道:
Agent_Spock wrote:

。 Trim()消除了hello和world之间的差距

.Trim() removes gap between hello and world



不会。它不会。


No. It won't.

删除来自当前String对象的所有前导和尾随空格字符

Removes all leading and trailing white-space characters from the current String object


尝试使用s.TrimStart()删除开头的空格和s.TrimEnd ()删除末尾的空格,只需删除s.Trim()以删除两边的空格;
Try s.TrimStart() to remove spaces at beginning and s.TrimEnd()to remove spaces at the end and simply s.Trim() to remove spaces on both sides;


这篇关于在c#win中删除字符串右侧的空格。形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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