积极答复者
请教如何处理—字符串数组移除元素首尾的空白

问题
答案
-
你好,String 类有Trim方法,专去空格。所以你可以先按, 分割,然后调用Trim方法就好了。
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 Mike FengModerator 2013年1月23日 11:35
- 已标记为答案 Mike FengModerator 2013年2月5日 11:05
-
或者你可以call string 类的replace方法,将一个空格 替换为空. 然后你就得到了一个不包含任何空格的字符串。你再按,分割就好了
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Mike FengModerator 2013年2月5日 11:05
全部回复
-
你好,String 类有Trim方法,专去空格。所以你可以先按, 分割,然后调用Trim方法就好了。
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 Mike FengModerator 2013年1月23日 11:35
- 已标记为答案 Mike FengModerator 2013年2月5日 11:05
-
或者你可以call string 类的replace方法,将一个空格 替换为空. 然后你就得到了一个不包含任何空格的字符串。你再按,分割就好了
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Mike FengModerator 2013年2月5日 11:05
-
请教如何处理—字符串数组移除元素首尾的空白
例如:
string s="123++,234++,...";//数组里面的元素都是utf-8编码的++是空格 string[] s1= s.Split(','); string s="123,234,...";//想变成这样,因为不确定空格多少个所以也不知道多少个加号,然后在赋值到数组 string[] s1= s.Split(',');
请教各位有什么方法处理谢谢可以尝试:
string s = " 123 ,2 ,456 ,7,8 ,9 "; s = s.Trim().Replace(' ','\0'); string[]values=s.Split(','); foreach (var item in values) { Console.WriteLine(item); }
帮助一起改进论坛质量?提交你的意见于此。
我的博客园
慈善点击,点击此处
和谐拯救危机,全集下载,净化人心
- 已编辑 ThankfulHeartModerator 2013年1月24日 5:48