How to replace a string in a string except first occurrence?
e.g. C:\\Test-Processed\1-Processed\2-Processed
should output
C:\\Test-Processed\1\2
Something like following:
string originalStr = "C:\\Test-Processed\\1-Processed\\2-Processed";
string temp = "-Processed";
string str = originalStr.Substring(0, originalStr.IndexOf(temp) + temp.Length);
originalStr = str + originalStr.Substring(str.Length).Replace(temp, "");
originalStr will be:
originalStr = "C:\\Test-Processed\\1\\2"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With