views:

76

answers:

1

Hello

What does the offset word mean in the context of programming? does mean in the beginning or by a distance.

what does string.offsetByCodePoints(int index, int codePointOffset) method exactly do?

And what do they mean in the documentation by Unpaired surrogates?

Thanks in advance for your help

A: 

According to the JavaDoc,

String.offsetByCodePoints(int index, int codePointOffset)

Returns the index within this object that is offset from {@code index} by {@code codePointOffset} code points.

Here is an example of usage...

int num = 0;
num = "Test_String".offsetByCodePoints(0, 2); //num is 2
num = "Test_String".offsetByCodePoints(3, 2); //num is 5
num = "Test_String".offsetByCodePoints(9, 5); //Throws an exception since offset goes out-of-bounds
Ryan Berger
`num = "Test_String".offsetByCodePoints(3, 2); //num is 6` prints 5 for me
org.life.java
Sorry, "off by 1" typo. Fixed now.
Ryan Berger
Thanks it is clear now
Skystar3