Replace words with proper upper/lower cases

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

I'm working on a word replacement program in .NET. I have a list of
words spelt in American English and need to replace them with
translated British spelling while keeping the upper or lower cases of
each letter in these words.

For instance, I have a dictionary below:

theater theatre
center centre
annualized annualised

Then I want to replace the applicable words in the dictionary in
American English with equivalent British words:

"I went to the CAPITAL THEATER on Center Street to see a show this
past weekend."

The result should be:

"I went to the CAPITAL THEATRE on Centre Street to see a show this
past weekend."

I have a loop through each word, and see if the word is in any of the
American words the the dictionary (by case-insensitive comparison),
but the challeging part is to replace the word with the equivalent
British word while keeping the original upper or lower case of each
letter in the word.

foreach (word in article)
{
MatchingWord = word.FindMatchingWord();
if (MatchingWord != "")
{
word = MatchingWord; //How to take care of the upper or
lower case of each letter here?

}

}

Any advice? Thanks!
 
Back
Top