如何把数组中的空值去掉

curd0468 2008-05-17 11:19:45
现有一组数组myWords[],其中有些值是空值,我如何将这myWords[]中空值去掉,把剩下的非空值留下组成另一组数组,应该怎么做,请指点
...全文
1228 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
curd0468 2008-05-17
  • 打赏
  • 举报
回复
搞定,多谢各位
Fibona 2008-05-17
  • 打赏
  • 举报
回复
List<string> strs = new List<string>();
foreach (string s in myWords)
{
if(! string.IsNullOrEmpty(s) ) strs.Add(s);
}
string[] result = strs.ToArray();

这样就行
贫僧又回来了 2008-05-17
  • 打赏
  • 举报
回复
string[] ss = new string[5] { "ss","55",string.Empty,"ee",string.Empty};
foreach(string s in ss)
{
ArrayList h = new ArrayList();
if (s != string.Empty)
{
h.Add(s);
foreach (string m in h)
{
MessageBox.Show(m);
}

}
}
仅供参考!
gomoku 2008-05-17
  • 打赏
  • 举报
回复

List<string> strs = new List<string>();
foreach (string s in myWords)
{
if(! string.IsNullOrEmpty(s) ) strs.Add(s);
}
string[] result = strs.ToArray();
XIEWH 2008-05-17
  • 打赏
  • 举报
回复
只知道循环判断...

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧