在C#中拆分字符串 [英] Spliting the string in c#
本文介绍了在C#中拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须拆分一个字符串并将结果放入另一个字符串中.
例如:
字符串test ="/n user /n/n/n";
我想分割上面的字符串,并将其放在新的字符串中,最终结果应该是这样的,
字符串result ="user";
我想消除字符串中的所有"/n"和空白,并将其余的字符串放入结果中.
请帮帮我.
谢谢,
Kiran
Hi,
I have to split a string and place the result into in another string.
Ex :
string test="/n user/n /n /n";
i want to split the above string and place that in a new string and the finaaly the result should be like this,
string result="user";
i want to eleminate all the "/n" and empty spaces in the string and place the remaining string in the result.
Please help me.
Thanks,
Kiran
推荐答案
String.Trim [ ^ ]应该可以完成您的工作想要.
String.Trim[^] should do the job you want.
使用正则表达式替换它们会更容易吗?像这样的东西:
Wouldn''t replacing them using a regex be easier? Something like:
Regex.Replace(test, @"\s+", "");
祝你好运!
Good luck!
从此处 [ ^ ].
这篇关于在C#中拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文