假设我需要像这样分割字符串:
输入字符串:"My. name. is Bond._James Bond!" 输出2个字符串:
- "My. name. is Bond"
- "_James Bond!"
我尝试了以下方法:
int lastDotIndex = inputString.LastIndexOf(".", System.StringComparison.Ordinal);
string firstPart = inputString.Remove(lastDotIndex);
string secondPart= inputString.Substring(lastDotIndex + 1, inputString.Length - firstPart.Length - 1);
有没有更优雅的提出方式?