C#分割字符串并删除空字符串 [英] c# split string and remove empty string
本文介绍了C#分割字符串并删除空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在拆分操作中删除空字符串和空字符串:
I want to remove empty and null string in the split operation:
string number = "9811456789, ";
List<string> mobileNos = number.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(mobile => mobile.Trim()).ToList();
我尝试过此操作,但这并没有删除空白项
I tried this but this is not removing the empty space entry
推荐答案
var mobileNos = number.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)
.Select(mobile => mobile.Trim()).Where(s => s != string.Empty).ToList();
或
var mobileNos = number.Replace(" ", "")
.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
这篇关于C#分割字符串并删除空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文