本文介绍了使用的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#)
发布评论