Replace words with proper upper/lower cases

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top