使用的string.join转换数组字符串后去除串多余的逗号(C#)

编程入门 行业动态 更新时间:2024-10-27 09:33:17
本文介绍了使用的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#)

本文发布于:2023-11-04 12:33:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557952.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:逗号   数组   字符串   多余   string

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!