从字符串中删除空格 [英] Remove whitespace from a string
本文介绍了从字符串中删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从字符串中删除任意数量的空格:
示例第一个字符串test1/test2//test3
示例第二个字符串test1/test2//test3
空格的数量不断变化,所以我想要一个能够处理这种不断变化的空格并仅生成这样的解决方案的方法
字符串test1/test2/test3
Thanks
How can i remove any number of whitespace from a string:
example 1st string test1/test2/ /test3
example 2nd string test1/test2/ /test3
the number of whitespace keeps changing so i want a solution that can handle this changing number of whitespace and just produces like this
string test1/test2/test3
thanks
推荐答案
请参见以下示例代码:
See this sample code:
string test1 = "test1/test2/ /test3";
test1 = test1.Replace(" ", ""); //remove white space
test1 = test1.Replace("//", "/"); //remove additional slashes
MessageBox.Show(test1);
将所有的''字符全部替换为('''')
replace all '' '' characters with nothing ('''')
这是伪代码.可以用C ++实现
This is pseodo code. Can be implemented in C++
这篇关于从字符串中删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文