Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StartsWith method C# doesn't return TRUE

I read some values from MS SQL database and I like to make some operations on string. Here is the code I am using to check if some string starts with another string:

String input = "Основното jавно обвинителство денеска поднесе пријава против БМ (59) од Битола заради постоење основи на сомнение дека сторил кривични дела „тешки дела против безбедноста на луѓето и имотот во сообраќајот“ и „неукажување помош на лице повредено во сообраќајна незгода“";
String subString = "Основното јавно обвинителство";
if (input.StartsWith(subString))
{
    Response.Write("OK");
}

However input.StartsWith(subString) does not return true. Does anybody have an idea why?

like image 246
vikifor Avatar asked Dec 28 '13 16:12

vikifor


People also ask

What is startsWith method?

The startsWith() method checks whether a string starts with the specified character(s). Tip: Use the endsWith() method to check whether a string ends with the specified character(s).

What is startsWith method in C#?

In C#, StartsWith() is a string method. This method is used to check whether the beginning of the current string instance matches with a specified string or not. If it matches then it returns the string otherwise false. Using foreach-loop, it is possible to check many strings.

What type of value is return by startsWith () method?

The JavaScript startsWith method is used to determine whether a string starts with a character or a particular string. The method returns a boolean true in case the string starts with the specified characters.

Is startsWith () case-sensitive?

The startsWith() method returns true if a string starts with a specified string. Otherwise it returns false . The startsWith() method is case sensitive.


1 Answers

The difference is in the character j in the position 10: its code is 106 in the input, but in your substring it's 1112 (0x458 - see demo).

Your second j comes from Unicode page 4

ј   1112    458 0xD1 0x98   CYRILLIC SMALL LETTER JE

It looks the same, but has a different code.

Re-typing j in the substring fixes this problem.

like image 189
Sergey Kalinichenko Avatar answered Sep 28 '22 09:09

Sergey Kalinichenko