我有一个构建地址字段的循环,其中一些字段在字符串末尾可能为空
List<string> list = new List<string>();
//list can contain any number of values, some of which might be "" (empty string)
string returnValue = "";
for (int iRow = 1; iRow <= list.Count; iRow++)
returnValue += String.Format("{0}, ", list[iRow]);
returnValue = returnValue.Trim();
我的输出是
asd, aaa, qwe, 123123, , , , ,
如何从字符串中删除尾随的“,”?
最佳答案
returnValue = returnValue.TrimEnd(' ', ',');
关于c# - 从字符串末尾删除多个 char 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1547595/