I am trying to take a block of text and scan it for specific text (name) and turn it into a URL, specifically:
Block of text:
Chairman Joe Smith has announced a new plan to decrease expenditures by outsourcing the planning of the new dining hall. Smith states the current project managers do not have excess time to commit to this new project and this will be less costly than hiring a new or contract project manager.
Now what I am trying to do is take any instances of Chairman Joe Smith, or Joe Smith, or Smith, or Chairman Smith and put that in a link to his profile/bio. Using any string methods that I know of (string replace, string builder, add text to before and after a matching string) I would run into the problem when scanning for Smith and then any of the other names.
If I try the following:
String.replace("Smith", "<a href='smithbio.html'>Smith</a>")
String.replace("Chairman Joe Smith", "<a href='smithbio.html'>Chairman Joe Smith</a>")
It would be bad because anywhere Smith is used as a part of his name fail and only Smith would be the link.
But if I try the opposite:
String.replace("Chairman Joe Smith", "<a href='smithbio.html'>Chairman Joe Smith</a>")
String.replace("Smith", "<a href='smithbio.html'>Smith</a>")
This will created nested links.
I am thinking maybe I should be using regex.Replace in combination with substring checks? But if so I am having trouble coming up with how to do it. How can I do these multiple replaces but say replace this string unless it's part of another string.replacer that is being called? FYI Doing this in VB, don't think it matters here but just in case...