## Reference.StringConstructor History

June 01, 2015, at 09:43 AM by Arturo -
Changed lines 55-63 from:
String stringOne = "Hello String"; // using a constant String
String stringOne = String('a'); // converting a constant char into a String
String stringTwo = String("This is a string"); // converting a constant string into a String object
String stringOne = String(stringTwo + " with more"); // concatenating two strings
String stringOne = String(13); // using a constant integer
String stringOne = String(analogRead(0), DEC); // using an int and a base
String stringOne = String(45, HEX); // using an int and a base (hexadecimal)
String stringOne = String(255, BIN); // using an int and a base (binary)
String stringOne = String(millis(), DEC); // using a long and a base
to:
String stringOne = "Hello String"; // using a constant String
String stringOne = String('a'); // converting a constant char into a String
String stringTwo = String("This is a string"); // converting a constant string into a String object
String stringOne = String(stringTwo + " with more"); // concatenating two strings
String stringOne = String(13); // using a constant integer
String stringOne = String(analogRead(0), DEC); // using an int and a base
String stringOne = String(45, HEX); // using an int and a base (hexadecimal)
String stringOne = String(255, BIN); // using an int and a base (binary)
String stringOne = String(millis(), DEC); // using a long and a base
String stringOne = String(5.698, 3); // using a float and the decimal places
June 01, 2015, at 09:29 AM by Arturo -
Changed lines 14-15 from:
* a float, using a specified decimal position
to:
* a float or double, using a specified decimal palces
Changed lines 38-39 from:
String(val, base)
to:
String(val, base)\\
String(val, decimalPlaces)
Changed lines 42-44 from:
val: a variable to format as a String - ''string'', ''char'', ''byte'', ''int'', ''long'', ''unsigned int'', ''unsigned long''\\
base (''optional'') - the base in which to format an integral value
to:
val: a variable to format as a String - ''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
June 01, 2015, at 09:24 AM by Arturo -
Changed lines 14-15 from:
to:
* a float, using a specified decimal position
Changed lines 18-19 from:
@@String thisString = String(13)@@
to:
(:source lang=arduino tabwidth=4:)
String thisString = String(13);
(:sourceend:)
Changed lines 24-25 from:
@@String thisString = String(13, HEX)@@
to:
(:source lang=arduino tabwidth=4:)
String thisString = String(13, HEX);
(:sourceend:)
Changed lines 30-31 from:
@@String thisString = String(13, BIN)@@
to:
(:source lang=arduino tabwidth=4:)
String thisString = String(13, BIN);
(:sourceend:)
Changed lines 51-52 from:
[@
to:

(:source lang=arduino tabwidth=4:)
Changed lines 62-63 from:
@]
to:
(:sourceend:)
February 12, 2013, at 01:03 PM by Roberto Guido - corrected binary conversion. Thanks chipselden for report
Changed lines 27-28 from:
gives you the String "1011", which is the binary representation of 13.
to:
gives you the String "1101", which is the binary representation of 13.
January 30, 2012, at 05:01 PM by Scott Fitzgerald -
Changed lines 57-58 from:
* [[StringAssignment | = (assignment)]]
* [[StringDestructor | ~String]]()
to:
* [[/Tutorial/StringConstructors | String Constructor Tutorial]]
August 13, 2010, at 11:47 PM by David A. Mellis -
Changed lines 1-2 from:
[[StringClass | String]]
to:
[[StringObject | String]]
August 08, 2010, at 07:24 PM by David A. Mellis -
August 08, 2010, at 07:18 PM by David A. Mellis -
Changed lines 6-7 from:
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).
to:
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

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". You can use other bases, however. 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 "1011", which is the binary representation of 13.
August 08, 2010, at 07:11 PM by David A. Mellis -
Changed line 13 from:
val: a variable to format as a String - ''string'', ''char'', ''byte'', ''int'', ''long'', ''unsigned int'', ''unsigned long''
to:
val: a variable to format as a String - ''string'', ''char'', ''byte'', ''int'', ''long'', ''unsigned int'', ''unsigned long''\\
August 08, 2010, at 07:11 PM by David A. Mellis -
[[StringClass | String]]

!!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).

!!!!Syntax
String(val)\\
String(val, base)

!!!!Parameters
val: a variable to format as a String - ''string'', ''char'', ''byte'', ''int'', ''long'', ''unsigned int'', ''unsigned long''
base (''optional'') - the base in which to format an integral value

!!!!Returns

an instance of the String class

!!!Examples

All of the following are valid declarations for Strings.
[@
String stringOne = "Hello String"; // using a constant String
String stringOne = String('a'); // converting a constant char into a String
String stringTwo = String("This is a string"); // converting a constant string into a String object
String stringOne = String(stringTwo + " with more"); // concatenating two strings
String stringOne = String(13); // using a constant integer
String stringOne = String(analogRead(0), DEC); // using an int and a base
String stringOne = String(45, HEX); // using an int and a base (hexadecimal)
String stringOne = String(255, BIN); // using an int and a base (binary)
String stringOne = String(millis(), DEC); // using a long and a base
@]