Reference.StringObject History

Hide minor edits - Show changes to output

November 13, 2013, at 01:48 PM by Scott Fitzgerald -
Changed lines 2-4 from:
to:
(:table width=100% border=0 cellpadding=5 cellspacing=0:)

(:cell width=67%:)
Added lines 11-31:
!!!!Examples
* [[Tutorial/StringConstructors]]
* [[Tutorial/StringAdditionOperator]]
* [[Tutorial/StringIndexOf]]
* [[Tutorial/StringAppendOperator]]
* [[Tutorial/StringLengthTrim]]
* [[Tutorial/StringCaseChanges]]
* [[Tutorial/StringReplace]]
* [[Tutorial/StringCharacters]]
* [[Tutorial/StringStartsWithEndsWith]]
* [[Tutorial/StringComparisonOperators]]
* [[Tutorial/StringSubstring]]

!!!!See Also

* [[string]]: character arrays
* [[http://arduino.cc/en/Reference/VariableDeclaration|Variable Declaration]]

(:cell width=33%:)

Changed lines 59-76 from:

!!!!Examples
* [[Tutorial/StringConstructors]]
* [[Tutorial/StringAdditionOperator]]
* [[Tutorial/StringIndexOf]]
* [[Tutorial/StringAppendOperator]]
* [[Tutorial/StringLengthTrim]]
* [[Tutorial/StringCaseChanges]]
* [[Tutorial/StringReplace]]
* [[Tutorial/StringCharacters]]
* [[Tutorial/StringStartsWithEndsWith]]
* [[Tutorial/StringComparisonOperators]]
* [[Tutorial/StringSubstring]]

!!!!See Also

* [[string]]: character arrays
* [[http://arduino.cc/en/Reference/VariableDeclaration|Variable Declaration]]
to:
(:tableend:)
November 13, 2013, at 01:41 PM by Scott Fitzgerald -
Added line 22:
* [[StringReserve | reserve]]()
Deleted line 53:
April 10, 2013, at 11:33 AM by Federico -
Added line 26:
* [[StringToInt | toInt()]]
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|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 [[string| 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
* [[StringConstructor | String]]()
* [[StringCharAt | charAt]]()
* [[StringCompareTo | compareTo]]()
* [[StringConcat | concat]]()
* [[StringEndsWith | endsWith]]()
* [[StringEquals | equals]]()
* [[StringEqualsIgnoreCase | equalsIgnoreCase]]()
* [[StringGetBytes | getBytes]]()
* [[StringIndexOf | indexOf]]()
* [[StringLastIndexOf | lastIndexOf]]()
* [[StringLength | length]]()
* [[StringReplace | replace]]()
* [[StringSetCharAt | setCharAt]]()
* [[StringStartsWith | startsWith]]()
* [[StringSubstring | substring]]()
* [[StringToCharArray | toCharArray]]()
* [[StringToLowerCase | toLowerCase]]()
* [[StringToUpperCase | toUpperCase]]()
* [[StringTrim | trim]]()

!!!!Operators
* [[StringBrackets | [] (element access)]]
* [[StringPlus | + (concatenation)]]
* [[StringComparison | == (comparison)]]
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
* [[http://arduino.cc/en/Reference/VariableDeclaration|Variable Declaration]]
''Examples:''
Added lines 47-52:

!!!!See Also

* [[string]]: character arrays
* [[http://arduino.cc/en/Reference/VariableDeclaration|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|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
* [[http://arduino.cc/en/Reference/VariableDeclaration|Variable Declaration]]
''Examples:''
* [[Tutorial/StringConstructors]]
* [[Tutorial/StringAdditionOperator]]
* [[Tutorial/StringIndexOf]]
* [[Tutorial/StringAppendOperator]]
* [[Tutorial/StringLengthTrim]]
* [[Tutorial/StringCaseChanges]]
* [[Tutorial/StringReplace]]
* [[Tutorial/StringCharacters]]
* [[Tutorial/StringStartsWithEndsWith]]
* [[Tutorial/StringComparisonOperators]]
* [[Tutorial/StringSubstring]]

Share