String functions

Provides a reference of string functions.

Table 1. String functions
Syntax Effect
String.fromCharCode(code)

Returns a single-character string containing the character with the given ASCII code.

Examples:

String.fromCharCode(65) –>"A"

writeln(String.fromCharCode(0x30)); –> "0"

parseInt(string [ , base ] )

Parses string as an integer written in the given base, and returns its value. If the string does not represent a valid integer, NaN is returned.

Leading white space characters are ignored. If parseInt encounters a character that is not a digit in the specified base, it ignores it and all succeeding characters and returns the integer value parsed up to that point.

If base is omitted, it is taken to be 10, unless string starts with 0x or 0X, in which case it is parsed in base 16, or with 0, in which case it is parsed in base 8.

Examples:

parseInt("123") –> 123

parseInt("-123") –> -123

parseInt("123.45") –> 123

parseInt("1001010010110", 2) –> 4758

parseInt("a9", 16) –> 169

parseInt("0xa9") –> 169

parseInt("010") –> 8

parseInt("123 poodles") –> 123

parseInt("a lot of poodles") –> NaN

parseFloat(string)

Parses string as a floating-point number and return its value. If the string does not represent a valid number, NaN is returned.

Leading white space characters are ignored. The string is parsed up to the first unrecognized character. If no number is recognized, the function returns NaN.

Examples:

parseFloat("-3.14e-15") –> -3.14e-15

parseFloat("-3.14e-15 poodles") –> -3.14e-15

parseFloat("a fraction of a poodle") –> NaN