I have the following string
an-ca
an-ca
If you will look it closely you will see that they are different!
To compare 2 string like this I found this solution:
if (String.Compare(str1, str2, StringComparison.InvariantCulture) == 0) ...
So I have 2 questions
-
Way W3C did characters so are the same in different languages – so make problems of comparision
-
How in C# I can convert the string to ‘InvariantCulture’
EDIT:
This link may explain the problem better
Thanks in advance
There are a lot of cases for mismatching especially with characters than have no visible differences. For example we assume that a space is always a 32 (0x20) byte. When the text comes from web a space may be a 160 (0xa0) which is the “ ” entity. And there are more spaces. The same may happen with hyphens, dots, commas etc. Check this page for more information and especially this one as it contains the most usual cases for this king of mismatches.
With the contained information you can write a function (preferably straight-forward for better performance – aka a long switch) to recreate a string that is already html decoded.
As a proof of concept I’m including the code I’m using for creating a friendly URL and at the same time keep a dictionary for tagging based on titles. It covers only Windows Western and Central European character sets including thorn and eth. As you see there are some tricky parts and of course a lot of space for customization. This spaghetti code makes only one pass to the initial string.
Use it as a guide for you initial requirement.
For the record it generates “c-cplusplus-articles” for “C/C++ articles” and not “c-c—articles” or “cc-articles”.