SHIP:Sail:codepointAt

From Serious Documentation
Jump to: navigation, search
Function Returns Introduced Description
codepointAt Integer v4.0 Returns the Unicode-16 codepoint (or ASCII numeric value for characters in the ASCII range) of a character at a specified index in a String.

See Also:

Prototype

Integer codepointAt(String s, Integer index);

Parameters/Return Value

Parameter Data Type Description
s String String to pull character from
index Integer index in string 0...(length-1)
Return Integer Unicode-16 codepoint value of character at index

Detailed Description

The codepointAt() function returns the 16-bit Unicode codepoint number for the character in the string at offset index.

The return value of codepointAt() is an Integer, not a Short, since Short is a signed 16-bit value and unable to hold the full range of the unsigned Unicode-16 value.

ASCII values will be 8 bit values, and therefore have a range of 0..255.

An negative index or an index beyond the end of the string will return the invalid codepoint -1.

Examples

Example Result Notes
codepointAt("hello",0); 104
codepointAt("hello",-1); -1 Invalid index
codepointAt("hello",20); -1 Invalid index
codepointAt("Wow™",3); 0x2122

References