且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从数组中删除空字符串

更新时间:2023-11-02 22:04:46

  var  MainSkill =  string  .Join( ,SkillId.Where(x = >  x! =  null &&!string.IsNullOrWhiteSpace(x.ToString()))); 


只需使用LINQ并解决它



  //  首先删除空字符串 
test = test.Where(x = &gt ; !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);