none
Unicode string compare problem RRS feed

  • Question

  • I face string compare problem 

    my code is like this

    var itemCategory = _itemCategoryDa.ReadAll().Any(m => m.ItemCategoryName.Equals(model.ItemCategoryName, StringComparison.Ordinal));

    and it return true for this two texts 

    ሰሃን 

    ብርጭቆ 

    which is completely different words in Amharic (Ethiopian language) / Unicode 

    the compare is not working, i tried different approach but it didnt any one with solution 


    Binyam Welday

    Wednesday, November 12, 2014 2:20 PM

Answers

  • No, c is false in the following case. Check for yourself:

          string a = "ሰሃን";
          string b = "ብርጭቆ";
    
          bool c = a.Equals(b, StringComparison.Ordinal);
    

    The values of the ItemCategoryName properties are not what you expect.

    Please remember to mark helpful posts as answer and/or helpful.

    Wednesday, November 12, 2014 2:58 PM

All replies

  • No, c is false in the following case. Check for yourself:

          string a = "ሰሃን";
          string b = "ብርጭቆ";
    
          bool c = a.Equals(b, StringComparison.Ordinal);
    

    The values of the ItemCategoryName properties are not what you expect.

    Please remember to mark helpful posts as answer and/or helpful.

    Wednesday, November 12, 2014 2:58 PM
  • Hello Binyam Welday,

    As Magnus mentions, check the code as the result of _itemCategoryDa.ReadAll() and see if both “ሰሃን“, ”ብርጭቆ” are in the collection. The Any method would do a loop comparison to check if the compared sting(model.ItemCategoryName in your case) exists in the returned collection, if it finds, it would return true.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, November 13, 2014 3:31 AM
    Moderator