I need to remove certain strings from a string, and I am thinking to use replace method. The problem is, this will replace a string with another, wherever it is found. For example,
string str = “123d456”
string result = str.Replace(“d”, “”)
The result will be “123456”, of course. How can I make this replace only for the beginning or the end of the string? For example,
string str = “d123d456”
string result = str.Replace(“d”, “”)
I want this result to be 123d456 instead of 123456. I want to only replace the string if it is at the beginning or the end of the string, and anything in the middle not to be affected by the method.
I don’t have to use replace method if there is a better way, but is there any way to do this?