本文介绍了在c#中字符串的开头和结尾添加逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个字符串变量,我必须concat.But之前我想检查每个字符串是否在开始和结束时都有逗号。如果它没有,那么在开始和结束时添加逗号,如果它有逗号,则删除它们我怎么做?

I have multiple string variables which i have to concat.But before that i want to check if every string has comma at start and end.If it doesnt have then add commas at start and end and if it has commas then remove them.How can i do this?

推荐答案

var rawStrings = myStringCollection.Select(s => s.Trim(','));
string concat = string.Join(",", rawStrings);

会这样做。



这篇关于在c#中字符串的开头和结尾添加逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:47