• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

I need to compare 2 similar strings and choose upper case when available

I have two instances of a name and need to merge them thusly:

Activity
activities

should create
Activities

How can I do this in C#?

newbieweb
0
newbieweb
Asked:
newbieweb
1 Solution
 
jerrypdCommented:
you need logic to determine how "similar" the words are to determine if they are the same.
for example Activities and activate, or active...
once you have that logic, then you just need to set the first character to uppercase.
But, given the weirdness of the english language, I think the hardest part will be the "rules" for similar words...
0
 
newbiewebSr. Software EngineerAuthor Commented:
thanks.
0
 
dimajCommented:
I'm not sure if this will work 100% of the time, but my approach would be as follows:
1) Loop through both strings character-by-character
2) Compare current character's ascii numbers
3a) If absolute value of ascii of  str1 - ascii of str2 == 32, then pick the one with a lower number (that's your upper case)
3b) if ascii of str1 == ascii of str2, pick whichever one you like
4) If you're at the end of one of the strings, go back one and append leftovers from the other string

4th step will basically handle your substitution of 'y' for 'ies'

I hope this will get you started.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now