c# - 如何操作字符串并从 asp.net c# 中的列表框绑定(bind)中删除 '\'

标签 c# asp.net string listbox

我在我的列表框中获得的值如下

\MRI_SCRUM_GIT\Iteration\AS-Automation,
\MRI_SCRUM_GIT\Iteration\Pluse Pheonix,
\MRI_SCRUM_GIT\Iteration\Pluse Pheonix\Sprint 1,
\MRI_SCRUM_GIT\Iteration\Pluse Pheonix\Sprint 10

但我希望它是这样的:

MRI_SCRUM_GIT\\Iteration\\AS-Automation,
MRI_SCRUM_GIT\\Iteration\\Pluse Pheonix,
MRI_SCRUM_GIT\\Iteration\\Pluse Pheonix\Sprint 1,
MRI_SCRUM_GIT\\Iteration\\Pluse Pheonix\Sprint 10

我的代码

string selectedITeration = string.Empty;

foreach (ListItem lis in ListIteration.Items)
{
    if (lis.Selected == true)
    {
        selectedITeration += lis.Text + ",";
    }
}

最佳答案

您需要Trim \:

char[] charsToTrim = { '\\'};
selectedITeration += (lis.Text.Trim(charsToTrim) + ",").Replace(@"\",@"\\"); 

关于c# - 如何操作字符串并从 asp.net c# 中的列表框绑定(bind)中删除 '\',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49595337/

相关文章:

c# - 二进制对象图序列化

java - 如何将一个字符串数组拆分为多个字符串?

JAVA从String转换为Binary,然后返回文件中的String

c# - Kafka Confluent 库中 poll 和 consume 的区别

c# - 只锁定 1 个操作?

c# - 使用反射在运行时向类添加新属性

带有行尾的 C++ 字符串用于归档空行

asp.net - 在 ASP.NET MVC 3 中更改 Membership.ValidateUser() 和其他内容

asp.net - 如何支持两种 URL

c# - Asp.NET 身份自定义 SignInManager