TrimEnd()不工作 [英] TrimEnd() not working
本文介绍了TrimEnd()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想,如果它的结尾修剪结束掉一个字符串,。这是一个逗号和空格。
我试过 TrimEnd('')
,但这不起作用。它必须是只有在字符串结尾这样,所以我不能只用上卸下摆臂
来删除最后两个字符。我该怎么办呢?
解决方案
字符串的txt =测试;
的txt = txt.TrimEnd(',',''); // TXT =测试
此使用超载 TrimEnd(PARAMS的char [] trimChars)
。您可以指定1个或多个字符将形成集字符去掉的。在这种情况下,逗号和空间。
I want to trim the end off a string if it ends in ", ". That's a comma and a space.
I've tried TrimEnd(', ')
, but this doesn't work. It has to be only if the string ends this way, so I can't just use .Remove
to remove the last two characters. How can I do it?
解决方案
string txt = "testing, ";
txt = txt.TrimEnd(',',' '); // txt = "testing"
This uses the overload TrimEnd(params char[] trimChars)
. You can specify 1 or more chars that will form the set of chars to remove. In this case comma and space.
这篇关于TrimEnd()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文