Take the 2-minute tour ×

Possible Duplicate:
Ignoring accented letters in string comparison

I am using a special framework for making this job (NHibernate, Castle). My problem is that; there is a website where people can search apartments, rooms etc. Most of these website users are Turkish. So my problem starts here.

For example if people search the word: Beşiktaş(it is a district name) they can search like this Besiktas. As you can see there are some special characters(S,Ş Ö O, Ğ G, Ç C, İ I, Ü U ) in Turkish and people might be using both of them. I have to search all conditions like this. For example if they try to search Beşiktaş i have to search all variants like:"Besiktaş, Beşiktaş, Besiktas Beşiktas" and after this operation I have to remove duplicated objects from my list. How can I make this dream come true :)

I Just need the algorithm of this operation.

Sorry for my poor English skills. Thank You

share|improve this question

marked as duplicate by J. Steen, Niranjan Kala, ChrisF, Firo, Lafada Nov 20 '12 at 12:12


what about Lucene? –  Lucene Nov 20 '12 at 10:15
add comment

1 Answer

You need to look into something called CultureInfo which can be leveraged to do this. Here is a similar question someone else asked regarding ignoring accented letters, which is pretty much the same as what you wish to do. Here is a method that was posted and accepted as an answer which will compare strings ignoring accented characters

string s1 = "hello";
string s2 = "héllo";

if (String.Compare(s1, s2, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) == 0)
    // both strings are equal

If you use this I would store the districts as their English names without accented letters and compare the string before you execute your query against your database. That way you would allow the user to use accented characters as well as their English names.

Here is a link to the MSDN article regarding CultureInfo

share|improve this answer
Hello Mark, Thank you for your answer. This is what i am looking for. But there is a problem using this for me. This search not only about district names it is searching many tables in my database. also i already stored lots of informations to the tables. I am trying to add my codes here but site is not allowing that because i am a new member :( –  Volkan Dursun Nov 20 '12 at 9:20
Depending on the volume of data I would try to change all of names in the database to plain English characters and allow the user to query using whatever accented characters they want and when you receive their query perform the above method. It shouldn't really matter that you have many tables to query against because the string will be sanitized before you execute the query. –  Mark Walsh Nov 20 '12 at 9:53
add comment
