使用的string.join转换数组字符串后去除串多余的逗号(C#) [英] Removing extra commas from string after using String.Join to convert array to string (C#)

查看:582
本文介绍了使用的string.join转换数组字符串后去除串多余的逗号(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里快速的问题。我转换的数组使用的string.join字符串。一个小问题我是这样的,在阵列中的一些指数持仓将会是空白。下面是一个例子:

Quick question here. I'm converting an array into a string using String.Join. A small issue I have is that, in the array some index positions will be blank. An example is below:

array[1] = "Firstcolumn"
array[3] = "Thirdcolumn"

使用的string.join(,阵);,我会得到以下内容:

By using String.Join(",", array);, I'll get the following:

Firstcolumn ,, Thirdcolumn

Firstcolumn,,Thirdcolumn

请注意了多余的。我怎样才能从字符串删除多余的逗号,或使用的string.join时,最好不要包括空白指数?

Note the extra ,. How can I remove the extra commas from the string, or ideally not include blank indices when using String.Join?

推荐答案

试试这个:):

var res = string.Join(",", array.Where(s => !string.IsNullOrEmpty(s)));

这将加入只有字符串这不是

This will join only the strings which is not null or "".

这篇关于使用的string.join转换数组字符串后去除串多余的逗号(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆