String to long integer and string characters

Hello, the target is to convert String to long integer, and i have a working funcion hex to byte, nice.

But, if i use String.toCharArray or String.substring, the 3 first bytes/characters are wrong.

Example:

Code:

String str2 = "<U+202D>capdepor<U+202C>";
Serial.println(str2);
Serial.println(str2.substring(0,2));
Serial.println(str2.substring(2,4));
Serial.println(str2.substring(4,6));
Serial.println(str2.substring(6,8));

Result:

<U+202D>capdepor<U+202C>
⸮
⸮c
ap
de

WHY?!¿

Is it always 3 bytes off?
isn't a string a character array with a terminator?
Which is the right way to split a string?

Thanks.

I think the file has some odd character encoding. If I cut and paste your code into a blank sketch, I see the same behavior.

If I type in what you have posted into a new sketch, it works as expected.

blh64:
I think the file has some odd character encoding. If I cut and paste your code into a blank sketch, I see the same behavior.

If I type in what you have posted into a new sketch, it works as expected.

Does look like something non-printing in the code posted, if I paste it into the IDE and backspace through "capdepor" there is an extra backspace needed between the " and c.

Looking at the code in a more basic text editor, after the opening quote is the unicode character 0x202D, and before the closing quote the unicode character 0x202C.