all. I am trying to code a word replacement tool that will find and replace multiple words at once. Here's my code:
IDictionary<string, string> wordDict = new Dictionary<string, string>();
wordDict[wordsToFind.Text] = wordsToReplace.Text;
string textToReplace = article.Text;
foreach (KeyValuePair<string, string> entry in wordDict)
{
textToReplace = textToReplace.Replace(entry.Key, entry.Value);
}
wordDict is simply a key,value array where the key is the word to find and the value is the word to replace the found word with. For example, one entry in this dictionary could look like drone->dog.
wordsToFind.Text and wordsToReplace.text should be self-explanatory. I'm just demonstrating how my wordDict dictionary is setup.
The article.text variable is just the textblock that has words which needs replacing.
The problem I am running into is when the word replacer hits capitalized words and doesn't recognize them as a word to replace (case-sensitive).
Without just simply lowercasing everything and replacing that way (or, I'll go for lowercasing everything if you also have a way to retain the original casing in the output), I am trying to find a way to basically detect those capitalized words, where the first letter is capitalized, and replace it accordingly with the same casing for the replacement word when the words in my wordDict variable are all lowercased.