String()
Description
Constructs an instance of the String class. There are multiple versions that construct Strings from different data types (i.e. format them as sequences of characters), including:
- 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
- A constant integer or long integer
- A constant integer or long integer, using a specified base
- 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: String thisString = String(13); gives you the String "13".
- However, you can use other bases. For example: String thisString = String(13, HEX); gives you the String "D", which is the hexadecimal representation of the decimal value 13.
- Or if you prefer binary, String thisString = String(13, BIN); gives you the String "1101", which is the binary representation of 13.
Syntax
Parameter Values
- 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.
- decimalPlaces: only if val is float or double. The desired decimal places.
Return Values
- An instance of the String class.
Example Code
All of the following are valid declarations for Strings.
Functions
- Language : String.charAt()
- Language : String.compareTo()
- Language : String.concat()
- Language : String.c_str()
- Language : String.endsWith()
- Language : String.equals()
- Language : String.equalsIgnoreCase()
- Language : String.getBytes()
- Language : String.indexOf()
- Language : String.lastIndexOf()
- Language : String.length()
- Language : String.remove()
- Language : String.replace()
- Language : String.reserve()
- Language : String.setCharAt()
- Language : String.startsWith()
- Language : String.substring()
- Language : String.toCharArray()
- Language : String.toDouble()
- Language : String.toInt()
- Language : String.toFloat()
- Language : String.toLowerCase()
- Language : String.toUpperCase()
- Language : String.trim()
Operators
- Language : [\] (element access)
- Language : + (concatenation)
- Language : += (append)
- Language : == (comparison)
- Language : > (greater than)
- Language : >= (greater than or equal to)
- Language : < (less than)
- Language : ≤ (less than or equal to)
- Language : != (different from)
- Example : String Tutorials
See Also
- Language : array
- Language : bool
- Language : boolean
- Language : byte
- Language : char
- Language : double
- Language : float
- Language : int
- Language : long
- Language : short
- Language : size_t
- Language : string
- Language : unsigned char
- Language : unsigned int
- Language : unsigned long
- Language : void
- Language : word
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Additionally, some links direct to products from our own brand, DIYables.