0
点赞
收藏
分享

微信扫一扫

C# Visual Studio 删除字符串数组中的空字符串

兽怪海北 2022-03-30 阅读 288
c#

@[删除字符串数组中的空字符串]

删除字符串数组中的空字符,删除字符串数组中的空格。

	string [] hexstring = new string[] { "0X31","0X32","0XC4","       0XE3","0XBA","0XC3",""};
	for (int i = 0; i < hexstring.Length; i++)
	{
	     hexstring[i]= hexstring[i].Replace(" ", "");//用空字符串替换空格
	}
// 上面运行完成后字符串数组为{ "0X31","0X32","0XC4","0XE3","0XBA","0XC3",""},数组长度为7
      //去除字符串数组中的空字符串
      hexstring = hexstring.Where(s => !string.IsNullOrEmpty(s)).ToArray();
//上面运行完成后字符串数组为{ "0X31","0X32","0XC4","0XE3","0XBA","0XC3"},数组长度为6


举报

相关推荐

0 条评论