我需要从另一个字符串中删除一个字符串的第一个匹配项(并且只删除第一个匹配项)。
下面是一个替换字符串 "\\Iteration"的例子:
ProjectName\\Iteration\\Release1\\Iteration1
会变成这样:
ProjectName\\Release1\\Iteration1
下面是一些代码:
const string removeString = "\\Iteration";
int index = sourceString.IndexOf(removeString);
int length = removeString.Length;
String startOfString = sourceString.Substring(0, index);
String endOfString = sourceString.Substring(index + length);
String cleanPath = startOfString + endOfString;
好像有很多代码。
所以我的问题是: 有没有一种更清晰、更易读、更简洁的方法来做到这一点?
 
                                
                             
                                
                             
                                
                             
                                
                             
                                
                             
                                
                            