如何从数组中删除空字符串 [英] How to remove empty string from array
本文介绍了如何从数组中删除空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数组我想将该数组值转换为字符串,当我没有插入任何值时它取第一个值然后逗号然后逗号
i想要删除该逗号
SkillId [0] = 1
SkillId [2] = 2
SkillId [3 ] =
var MainSkill = string.Join(,,SkillId);
Tst.Skill = MainSkill;
这里它来了1,2 ,,
如何删除最后一个cooma或者在那里添加0
解决方案
var MainSkill = string .Join( ,,SkillId.Where(x = > x! = null &&!string.IsNullOrWhiteSpace(x.ToString())));
< blockquote>只需使用LINQ并解决它
// 首先删除空字符串
test = test.Where(x = > ; !string.IsNullOrEmpty(SkillId))。ToArray();
// 现在连接它
var MainSkill = string .Join( ,,test);
i have an array i want to convert that array value to string ,when i am not inserting anything value its taking 1st value then comma then comma
i want to delete that comma
SkillId[0]=1
SkillId[2]=2
SkillId[3]=""
var MainSkill = string.Join(",", SkillId);
Tst.Skill = MainSkill;
here its coming "1,2,,"
how to delete the last cooma or add 0 there
解决方案
var MainSkill = string.Join(",", SkillId.Where(x => x != null && !string.IsNullOrWhiteSpace(x.ToString())));
Just use LINQ and get it resolve
//first remove empty string test = test.Where(x => !string.IsNullOrEmpty(SkillId)).ToArray(); //now concatenate it var MainSkill = string.Join(",", test);
这篇关于如何从数组中删除空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文