用修剪方法在我的程序中出现问题 [英] Problem in myprogram with trim method
本文介绍了用修剪方法在我的程序中出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里我正在练习字符串方法.在使用trim方法的同时,我没有得到预期的输出.我正在获得与输出相同的字符串.请有人帮我做错了什么.
here i am practising with string methods.while using trim method ,i am not getting expected output.i am getting same string as a output.someone please help me what mistake i have done.
string s = "Hello World";
string removespace =s.Trim();
Console.Write(removespace);
Console.ReadKey();
推荐答案
Trim仅删除前导字符和尾随字符.
如果要删除中间的一个,请使用替换,例如
s.Replace(" ",String.Empty);
在代码行中,我们在String的任何位置都用空格char和空字符串char替换了.
Trim only removes leading and trailing chars.
If you want to remove the one in the middle also then use replace, e.g.
s.Replace(" ",String.Empty);
in the line of code, we are replacing a Space char with and empty string char, in any position of String s.
您误解了方法Trim
,
Trim
方法仅删除所有前导和尾随空格,而不会从中间删除.
要完成您的解决方案,您可以使用Replace
Method
即
You are misunderstanding the methodTrim
,
Trim
method only removes all leading and trailing whitespace, It doesn''t remove from the middle.
for accomplish your solution you can useReplace
Method
i.e
s.Replace(" ","");
这将为您提供所需的输出.
如果有帮助,请 投票 和 接受答案 .
That will give you desired output.
Please vote and Accept Answer if it Helped.
来自MSDN , String.Trim方法 [
From MSDN, String.Trim Method[^]:
Trim()从当前String对象中删除所有前导和尾随空格字符.
Trim() Removes all leading and trailing white-space characters from the current String object.
那么,您认为预期的输出是多少?
顺便说一句:也许您对 String.Split方法 [ ^ ].
:)
So, what is, in your opinion, the expected output?
BTW: Maybe you''re interested in String.Split Method[^].
:)
这篇关于用修剪方法在我的程序中出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文