C# 创建一个列表<;字符串>;从列表中,在最后一个逗号处断开
我需要在最后一个逗号上拆分一个字符串。如果只有一个逗号的话,我有一个有效的方法C# 创建一个列表<;字符串>;从列表中,在最后一个逗号处断开,c#,C#,我需要在最后一个逗号上拆分一个字符串。如果只有一个逗号的话,我有一个有效的方法 var ident = identNumbers.Split(',').ToList(); 我的字符串是使用Jquery/CSS格式化的,它是从一个JSON字符串派生的,该字符串不包含任何新行字符 字符串如下所示: Special Interest Entity (SIE) / Sanctions Lists / State Owned Company,Special Interest Entity (SIE)
var ident = identNumbers.Split(',').ToList();
我的字符串是使用Jquery/CSS格式化的,它是从一个JSON字符串派生的,该字符串不包含任何新行字符
字符串如下所示:
Special Interest Entity (SIE) / Sanctions Lists / State Owned Company,Special Interest Entity (SIE) / Enhanced Country Risk / State Owned Company
最后我需要一个列表,如下所示:
var input = "foo, bar, sample1, sample2 sample3";
var last = input.LastIndexOf(',');
var result = new[] {input.Substring(0, last), input.Substring(last+1).Trim()};
- 特殊利益实体(SIE)/制裁名单/国有公司
- 特殊利益实体(SIE)/强化国家风险/国有公司
- 我想,你需要这样的东西:
var input = "foo, bar, sample1, sample2 sample3";
var last = input.LastIndexOf(',');
var result = new[] {input.Substring(0, last), input.Substring(last+1).Trim()};
result
包含两个元素:“foo,bar,sample1”
和“sample2 sample3”
您所拥有的代码有什么问题?为什么要展示一个与您当前的方法兼容的示例?你能举一个例子说明这个问题吗?看起来你的代码应该可以完成这项工作