c# - 从字符串末尾删除多个 char 类型

标签 c# string

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

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/

相关文章:

python - 反转 Python 字符串的切片

c++ - UTF-8 字符串迭代器

c# - 将字符串转换为 byte[] 会创建零字符

c# - 使用连接到 LDAP 服务器的生物识别系统验证窗口用户

C# 正则表达式 for/"在字符串末尾

c# - 如果行 "---",如何用 itextsharp 画一条线?

java - 将字符串中的随机整数分配给字符

javascript - 如果 JavaScript 中有一个类名称字符串,如何访问该类?

c# - 使用 JSON 将继承的对象传递给 WCF 服务

c# - PagedList与ViewModels和.Skip()。Take()一起使用