Reference.StringObject History

Hide minor edits - Show changes to markup

November 16, 2014, at 11:53 AM by Arturo -
Changed line 13 from:
to:
Added line 61:
November 16, 2014, at 11:40 AM by Arturo -
Added line 19:
November 16, 2014, at 10:25 AM by Arturo -
Added line 44:
Changed lines 56-57 from:
to:
November 14, 2014, at 02:11 PM by Arturo -
November 14, 2014, at 01:26 PM by Arturo -
Changed line 51 from:
to:
Changed lines 56-61 from:
to:
Added lines 61-65:
November 10, 2014, at 12:16 PM by Arturo -
Changed line 51 from:
to:
November 10, 2014, at 12:10 PM by Arturo -
Changed lines 55-61 from:
to:
November 10, 2014, at 10:36 AM by Arturo -
Added line 51:
November 13, 2013, at 01:48 PM by Scott Fitzgerald -
Changed lines 2-4 from:
to:
Added lines 11-31:
Changed lines 59-76 from:
to:
November 13, 2013, at 01:41 PM by Scott Fitzgerald -
Added line 22:
Deleted line 53:
April 10, 2013, at 11:33 AM by Federico -
Added line 26:
August 15, 2010, at 08:49 PM by Tom Igoe -
August 13, 2010, at 11:46 PM by David A. Mellis -
Changed lines 5-8 from:

The String library, part of the core as of version 0019, allows you to use and manipulate strings of text in more complex ways than the string character array does. You can concatenate Strings, append to them, search for and replace substrings, and more. It takes more memory than a simple character array, but it is also more useful.

For reference, constant character arrays are referred to as strings with a small s, and String objects are referred to as Strings with a capital S.

to:

The String class, part of the core as of version 0019, allows you to use and manipulate strings of text in more complex ways than character arrays do. You can concatenate Strings, append to them, search for and replace substrings, and more. It takes more memory than a simple character array, but it is also more useful.

For reference, character arrays are referred to as strings with a small s, and instances of the String class are referred to as Strings with a capital S. Note that constant strings, specified in "double quotes" are treated as char arrays, not instances of the String class.

Functions

Operators

Deleted lines 35-80:

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

Possible ways to declare strings

  • use a constant string of characters, in double quotes
  • use a single constant character, in single quotes
  • Cast a constant string of characters into a String object
  • Concatenating two String objects, or a String object and a constant string of characters.
  • use a constant integer. The integer will be cast into the character array that represents it. See below for details
  • use a constant integer and a base value. The integer will be cast into a character array that represents in the base. See below for details.
  • use a constant long integer, or a variable integer or long integer. Works the same way as using a constant integer or long integer.

Constant integer Strings

Declaring a String with a constant 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.

Experienced programmers may be wondering how to declare a String of a fixed length of 13 characters. There's no constructor for that, because Strings can be added to through concatenation, or shortened through using trim().

See Also

  • string simple character arrays holding text strings
  • Variable Declaration

Examples:

Added lines 47-52:

See Also

  • string: character arrays
  • Variable Declaration
August 13, 2010, at 11:29 PM by Tom Igoe -
Added lines 1-66:

String

Description

The String library, part of the core as of version 0019, allows you to use and manipulate strings of text in more complex ways than the string character array does. You can concatenate Strings, append to them, search for and replace substrings, and more. It takes more memory than a simple character array, but it is also more useful.

For reference, constant character arrays are referred to as strings with a small s, and String objects are referred to as Strings with a capital S.

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

Possible ways to declare strings

  • use a constant string of characters, in double quotes
  • use a single constant character, in single quotes
  • Cast a constant string of characters into a String object
  • Concatenating two String objects, or a String object and a constant string of characters.
  • use a constant integer. The integer will be cast into the character array that represents it. See below for details
  • use a constant integer and a base value. The integer will be cast into a character array that represents in the base. See below for details.
  • use a constant long integer, or a variable integer or long integer. Works the same way as using a constant integer or long integer.

Constant integer Strings

Declaring a String with a constant 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.

Experienced programmers may be wondering how to declare a String of a fixed length of 13 characters. There's no constructor for that, because Strings can be added to through concatenation, or shortened through using trim().

See Also

  • string simple character arrays holding text strings
  • Variable Declaration

Examples:

Share