I have a large string value and I am trying to find the best way to replace a certain text value out of it without changing any values in a URL.
For instance lets say I want to replace the word "google" with "hello". I have a large string value with multiple instances of "hi" and a url within the string value "https://www.google.com" (this is just an example). Which is the best route to take for replacing these values, potentially a split on the string, regex or a replace?
At the moment I have something like this:
var data = "<h1>google this is a sample text</h1><p> more text will go here so, google. <a href='https://google.com'> Link here </a>";
var test = "";
if(data.Contains("google")){
test = data.Replace("google", "hello");
}
// for case sensitivity
if(data.Contains("Google")){
test = data.Replace("Google", "hello");
}
Is there a better alternative to this and would there be a way to not replace the text in a url?