Return the position of the next Unicode code point in a string after a specified position.
var nextCodePointIndex = require( '@stdlib/string/next-code-point-index' );Returns the position of the next Unicode code point in a string after a specified position.
var out = nextCodePointIndex( 'last man standing' );
// returns 1By default, the function searches for a Unicode code point starting from the first index. To specify an alternative starting search index, provide a fromIndex argument.
var out = nextCodePointIndex( 'last man standing', 4 );
// returns 5- If
stringis an empty string, the function returns-1irrespective offromIndex. - If a code point does not exist after
fromIndex, the function returns-1. - Note that
fromIndexdoes not refer to a visual character position, but to an index in the ordered sequence of UTF-16 code units.
var nextCodePointIndex = require( '@stdlib/string/next-code-point-index' );
var out = nextCodePointIndex( 'last man standing', 4 );
// returns 5
out = nextCodePointIndex( 'presidential election', 8 );
// returns 9
out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 );
// returns 2
out = nextCodePointIndex( '🌷', 0 );
// returns -1Usage: next-code-point-index [options] [<string>]
Options:
-h, --help Print this message.
-V, --version Print the package version.
--from index Starting search position in string. Default: 0.
$ next-code-point-index --from=0 𐒻𐓟𐒻𐓟
2To use as a standard stream,
$ echo -n '𐒻𐓟𐒻𐓟' | next-code-point-index --from=0
2