Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.StartsWith not Working when next character is the Prime Symbol (char)697

I am trying to use a string with the Prime symbol in it, but I am having some issues with the String.StartsWith method. Why is the following code throwing the exception?

string text_1 = @"123456";
string text_2 = @"ʹABCDEF";

string fullText = text_1 + text_2;
if (!fullText.StartsWith(text_1))
{
    throw new Exception("Unexplained bad error.");
}

I suspect that the issue is because this Prime symbol (char)697 is being treated as an accent and so is changing the letter before it. (I don't think it should be - it should be the the prime symbol and so should not be changing the numerical numbers in front of it). I am not exactly sure how to go about testing this. I did try the method proposed in this answer but it returned false:

IsLetterWithDiacritics(text_1[5]) //  == False
IsLetterWithDiacritics(fullText[5]) // == False
IsLetterWithDiacritics(fullText[6]) // == False

Thanks for any help.

like image 892
Ben Avatar asked Oct 02 '15 16:10

Ben


People also ask

How do you check if a string starts with a character?

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).

How do you check if a string starts with a specific character in Python?

The startswith() method returns True if the string starts with the specified value, otherwise False.

How do you check if a string starts with another string 6 14?

You can use ECMAScript 6's String. prototype. startsWith() method. It's supported in all major browsers.

How do you check if a string starts with a character 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.


1 Answers

ʹ or MODIFIER LETTER PRIME is a spacing modifier letter. It's not a true character but a special use symbol that modifies the preceding character.

From MSDN:

A modifier letter is a free-standing spacing character that, like a combining character, indicates modifications of a preceding letter.


string.StartsWith is returning false because in your concatenated string, the 6 is actually modified by the prime symbol that is appended after it.

like image 198
Scorpion Avatar answered Sep 29 '22 02:09

Scorpion