Reference.StringClass History

Hide minor edits - Show changes to output

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 [[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)]]

!!!!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:
(:redirect StringObject :)
August 08, 2010, at 08:20 PM by David A. Mellis -
Added line 13:
* [[StringConcat | concat]]()
Added line 17:
* [[StringGetBytes | getBytes]]()
Added line 21:
* [[StringReplace | replace]]()
Added line 25:
* [[StringToCharArray | toCharArray]]()
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:
!!!!Operators
* [[StringBrackets | [] (element access)]]
* [[StringPlus | + (concatenation)]]
* [[StringComparison | == (comparison)]]
Added lines 26-30:
!!!!Operators
* [[StringBrackets | [] (element access)]]
* [[StringPlus | + (concatenation)]]
* [[StringComparison | == (comparison)]]
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|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.
Changed line 46 from:
* [[string]]: simple character arrays holding text strings
to:
* [[string]]: character arrays
August 08, 2010, at 06:55 PM by David A. Mellis -
Changed lines 16-30 from:
to:
* [[StringCharAt | charAt]]()
* [[StringCompareTo | compareTo]]()
* [[StringEndsWith | endsWith]]()
* [[StringEquals | equals]]()
* [[StringEqualsIgnoreCase | equalsIgnoreCase]]()
* [[StringIndexOf | indexOf]]()
* [[StringLastIndexOf | lastIndexOf]]()
* [[StringLength | length]]()
* [[StringSetCharAt | setCharAt]]()
* [[StringStartsWith | startsWith]]()
* [[StringSubstring | substring]]()
* [[StringToLowerCase | toLowerCase]]()
* [[StringToUpperCase | toUpperCase]]()
* [[StringTrim | trim]]()
August 08, 2010, at 06:52 PM by David A. Mellis -
Changed lines 10-11 from:
* [[StringBrackets | \[\]]]
to:
* [[StringBrackets | [] (element access)]]
* [[StringPlus | + (concatenation)]]
* [[StringComparison | == (comparison)]]
August 08, 2010, at 06:50 PM by David A. Mellis -
Added lines 9-14:
!!!!Operators
* [[StringBrackets | \[\]]]

!!!!Functions
* [[StringConstructor | String]]()
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
* [[http://arduino.cc/en/Reference/VariableDeclaration|Variable Declaration]]
''Examples:''
Added lines 27-32:

!!!!See Also

* [[string]]: simple character arrays holding text strings
* [[http://arduino.cc/en/Reference/VariableDeclaration|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|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