0

I create wpf application. And some case I compare two string values. local value comes from richtextbox, and richtextbox value comes from word document. I try every solution on this site. But nothing changed. The comparision equal to false. I try replace end of file with linkedWord.Replace((char)160, (char)32);

Try string.Compare

String.Compare(wr.Orthography, linkedWord, StringComparison.OrdinalIgnoreCase) == 0

Use Encoding to byte array and SequanceEqual and more, but can not find solution. Please help me to solve this problem.

The value comes from richtextbox: enter image description here

the value comes from database:

enter image description here

EDIT:

After Compare method result is -1

Community
  • 1
  • 1
Elvin Mammadov
  • 25,329
  • 11
  • 40
  • 82
  • why words.Any()?? You can Directly Compare strings – yash Jan 07 '16 at 11:53
  • I need to check in database has any word to equal selected word in richtextbox – Elvin Mammadov Jan 07 '16 at 11:55
  • @yash because "words" is a collection and "any" is a quick way to check if "any" of the elements matches a condition before performing any further operation. Yes you could even implement your own loop, but why not since the framework offers these ready to go tools... ;-) – Leonardo Spina Jan 07 '16 at 11:56
  • @Elvin a piece of code to reproduce the issue would help to help... – Leonardo Spina Jan 07 '16 at 11:58
  • Hi @FarhadJabiyev. I can't look at its result, because can't access inside lambda expression method Any – Elvin Mammadov Jan 07 '16 at 11:58
  • 1
    What are the other properties in the collection item? There seems to be 3 Orth* properties. Are you comparing with the correct one? Also you can modify your lambda to help with the debugging to extract the variables from the item and write the to Debug etc just remember to return boolean for the Any() as the last statement. – Janne Matikainen Jan 07 '16 at 12:00
  • Actually you CAN access the condition within any for every member by seting a breakpoint. Mark the text with the actual condition, right-clkick and chose "set breakpoint". Thus you can break at every iteration. – MakePeaceGreatAgain Jan 07 '16 at 12:01
  • @JanneMatikainen, this code works for other words more than one week. – Elvin Mammadov Jan 07 '16 at 12:04
  • @FarhadJabiyev, I edited my question – Elvin Mammadov Jan 07 '16 at 12:07
  • What is the second character in the strings (it looks unusual)? Can you check if `s1.Length == s2.Length` and also `s1[1] == s2[1]` – Ivan Stoev Jan 07 '16 at 12:12
  • I'd try to compare problematic strings character by character to pinpoint the problem - even though they might "look" the same, it doesn't mean they're equal. – Grx70 Jan 07 '16 at 12:13
  • I check .Length == .Legth and they are same – Elvin Mammadov Jan 07 '16 at 12:13

1 Answers1

1

The reason is probably that cyrillic ә(ә) and latin ə(ə) are different though they look same.

Check each character for equality, below you can see the difference:

foreach (char c in "bәse")
    Console.Write(((int)c).ToString("0000"));

Console.WriteLine("\n--------------------");

foreach (char c in "bəse")
    Console.Write(((int)c).ToString("0000"));

Console.WriteLine("\n--------------------");

Console.WriteLine(("bәse"=="bəse").ToString());

Output

0098124101150101
--------------------
0098060101150101
--------------------
False

DOTNETFIDDLE

In this case you should replace the cyrillic chars with latin counterparts

You can see here and also check here, it seems like there is a library that can be used in this case

Community
  • 1
  • 1
mkb
  • 1,106
  • 1
  • 18
  • 21