我需要从另一个字符串中删除一个字符串的第一个(并且只有第一个)出现。
这是替换字符串的示例"\\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;
似乎很多代码。
所以我的问题是:是否有一种更清洁/更易读/更简洁的方式来做到这一点?
æ
和ae
被认为是平等的。试图删除paedia
从Encyclopædia
将抛出ArgumentOutOfRangeException
,因为你正在试图删除6个字符时,仅匹配串中包含5