循环后删除文本

SQL*_*ing -2 c# string

我有一个for循环,在字符串的末尾添加了radiobutton文本.这是代码:

for (int i = 0; i < listView1.CheckedItems.Count; i++)
                {
                    sqlQry.Text += listView1.CheckedItems[i].Text + radioButton9.Text;
                }  
Run Code Online (Sandbox Code Playgroud)

有没有办法radioButton9.Text在循环结束后修剪?

就像是:

sqlQry.Text = sqlQry.Text.TrimEnd(',');    
Run Code Online (Sandbox Code Playgroud)

现在结果是这样的:"A和B和C和"
我希望它是:"A和B和C"
我确实尝试了我提到的代码,但我不能使用:

sQlQry.Text=sqlQry.Text.TrimEnd(radioButton9.Text);
Run Code Online (Sandbox Code Playgroud)

fub*_*ubo 6

你可以用 string.Join

sqlQry.Text = string.Join(radioButton9.Text, listView1.CheckedItems.Cast<ListViewItem>().Select(x => x.Text));
Run Code Online (Sandbox Code Playgroud)