I'm having some issues with replacing words in a string with values from a dictionary. Here's a small sample of my current code:
Dictionary<string, string> replacements = new Dictionary<string, string>()
{
{"ACFT", "AIRCRAFT"},
{"FT", "FEET"},
};
foreach(string s in replacements.Keys)
{
inputBox.Text = inputBox.Text.Replace(s, replacements[s]);
}
When I execute the code, if I have ACFT
in the textbox, it is replaced with AIRCRAFEET
because it sees the FT
part in the string. I need to somehow differentiate this and only replace the whole word.
So for example, if I have ACFT
in the box, it should replace it with AIRCRAFT
. And, if I have FT
in the box, replace it with FEET
.
So my question is, how can I match whole words only when replacing words?
EDIT: I want to be able to use and replace multiple words.