top of page

03 Variables

String()

  • a constant string of characters, in double quotes (i.e. a char array)

  • a single constant character, in single quotes

  • another instance of the String object

  • an integer or long integer variable

  • an integer or long integer variable, using a specified base

  • a float or double, using a specified decimal places


Constructing a String from a number results in a string that contains the ASCII representation of that number. The default is base ten, so



gives you the String "13".


You can use other bases, however. For example,

gives you the String "d", which is the hexadecimal representation of the decimal value 13.


Or if you prefer binary,

gives you the String "1101", which is the binary representation of 13.

String(val)

String(val, base)

String(val, decimalPlaces)


val:       a variable to format as a String. Allowed data types: string, char, byte, int, long, unsigned int, unsigned long, float, double.


base:    (optional) the base in which to format an integral value.


decimalPlacesonly if val is float or double. The desired decimal places.


Returns

An instance of the String class.


Method Examples



© 2021 Odyssey Navigator. All rights reserved.

bottom of page