我有一个建立地址字段的循环,其中某些字段在字符串末尾可能为空

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(' ', ',');

10-04 17:56