Reference.StringClass History

Hide minor edits - Show changes to markup

August 13, 2010, at 11:47 PM by David A. Mellis -
Changed lines 1-52 from:

String

Description

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

Examples

See Also

  • string: character arrays
  • Variable Declaration
to:
August 08, 2010, at 08:20 PM by David A. Mellis -
Added line 13:
Added line 17:
Added line 21:
Added line 25:
August 08, 2010, at 07:09 PM by David A. Mellis -
Changed lines 7-8 from:

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.

to:

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.

August 08, 2010, at 06:59 PM by David A. Mellis -
Deleted lines 8-12:
Added lines 26-30:
August 08, 2010, at 06:56 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.

Changed line 46 from:
  • string: simple character arrays holding text strings
to:
August 08, 2010, at 06:55 PM by David A. Mellis -
Changed lines 16-30 from:
to:
August 08, 2010, at 06:52 PM by David A. Mellis -
Changed lines 10-11 from:
to:
August 08, 2010, at 06:50 PM by David A. Mellis -
Added lines 9-14:

Operators

Functions

Deleted lines 15-60:

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 27-32:

See Also

  • string: simple character arrays holding text strings
  • Variable Declaration
August 08, 2010, at 06:46 PM by David A. Mellis -
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