Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns a new string that is a substring of this string.
- * The surrogate pair is taken into consideration.
- */
- final class SubstringSample {
- static String substring(String source, int startCodePoints) {
- final int endCodePoints = source.codePointCount(0, source.length());
- return substring(source, startCodePoints, endCodePoints);
- }
- static String substring(String source, int startCodePoints, int endCodePoints) {
- final int startIndex = source.offsetByCodePoints(0, startCodePoints);
- final int endIndex = source.offsetByCodePoints(startIndex, endCodePoints - startCodePoints);
- return source.substring(startIndex, endIndex);
- }
- }
Add Comment
Please, Sign In to add comment