如何在 C# 中获取字符串中逗号 (,) 之前的所有元素? 例如 如果我的字符串是 say
string s = "a,b,c,d";
然后我想要 d 之前的所有元素,即最后一个逗号之前。所以我的新字符串 shout 看起来像
string new_string = "a,b,c";
我试过拆分,但一次只能拆分一个特定元素。
最佳答案
string new_string = s.Remove(s.LastIndexOf(','));
关于c# - c#中字符串中最后一个逗号之前的所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6646032/