I have a string like
string text="~aaa~bbb~ccc~bbbddd";
The input value will be : bbb
So in the above string i should remove the value "~bbb"
The resulting string should be
text="~aaa~ccc~bbbddd";
I'm not sure what are you wanna do but if i've got it you can do this :
private string ReplaceFirstOccurrence(string Source, string Find, string Replace)
{
int Place = Source.IndexOf(Find);
string result = Source.Remove(Place, Find.Length).Insert(Place, Replace);
return result;
}
var result =ReplaceFirstOccurrence(text,"~"+input,"");
One way would be:
string text = "~aaa~bbb~ccc~bbbddd";
string newStr = string.Join("~", text.Split('~').Where(r => r != "bbb"));
But if performance is the consideration then consider some other solution
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