如何删除前两个和最后两个字符的字符串? [英] How to remove first two and last two chars in a string?
本文介绍了如何删除前两个和最后两个字符的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个简单的方法来消除在字符串中的第2和最后2个字符
我有这个字符串:
\\\
TESTSTRING\\\
我怎么能轻易删除呢?
解决方案
海峡= str.Substring(2,STR 。长度-4)
当然,你必须测试该字符串包含超过4个字符在此之前。另外,在你的情况似乎\\\
是一个换行符。如果你想要做的是去除前导和尾部空格,你应该使用
str.Trim()
由查尔斯建议
Is there an easy way to remove the first 2 and last 2 chars in a string?
I have this string:
\nTESTSTRING\n
How could I easily delete them?
解决方案
str = str.Substring(2,str.Length-4)
Of course you must test that the string contains more than 4 chars before doing this. Also in your case it seems that \n is a single newline character. If all you want to do is remove leading and trailing whitespaces, you should use
str.Trim()
as suggested by Charles
这篇关于如何删除前两个和最后两个字符的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文