在C#中的模式后获取子字符串

Los*_*les 2 c#

希望在最后一个逗号或最后一个管道之后获取子字符串.所以说我有一个字符串可以是:"pipe | delimited | string"或"逗号,分隔符,字符串",结果在两种情况下都应该是"string".

我在lastindexof上查看C#的子字符串,但我不知道如何为管道和逗号执行此操作.像这样:str.Substring(str.LastIndexOf('|'或',')).有任何想法吗?

Kei*_*las 8

这有一个很好的功能.

str.LastIndexOfAny(new []{',','|'});
Run Code Online (Sandbox Code Playgroud)