Skip to content

Commit d365943

Browse files
author
SimonePDA
authored
Update stringObject.adoc
Updated content according to latest StringObject description
1 parent 2dfc266 commit d365943

File tree

1 file changed

+90
-19
lines changed

1 file changed

+90
-19
lines changed

Language/Variables/Data Types/stringObject.adoc

Lines changed: 90 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
2-
title: "String"
3-
categories: [ "Variables" ]
4-
subCategories: [ "Data Types" ]
2+
title: "String()"
3+
categories: [ "Data Types" ]
4+
subCategories: [ "StringObject Function" ]
55
---
66

77
:source-highlighter: pygments
88
:pygments-style: arduino
99

1010

1111

12-
= String
12+
= String()
1313

1414

1515
// OVERVIEW SECTION STARTS
@@ -18,14 +18,94 @@ subCategories: [ "Data Types" ]
1818

1919
[float]
2020
=== Description
21-
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.
22-
23-
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.
21+
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:
22+
23+
* a constant string of characters, in double quotes (i.e. a char array)
24+
* a single constant character, in single quotes
25+
* another instance of the String object
26+
* a constant integer or long integer
27+
* a constant integer or long integer, using a specified base
28+
* an integer or long integer variable
29+
* an integer or long integer variable, using a specified base
30+
* a float or double, using a specified decimal palces
31+
32+
Constructing a String from a number results in a string that contains the ASCII representation of that number. The default is base ten, so
33+
[source,arduino]
34+
----
35+
String thisString = String(13);
36+
----
37+
gives you the String "13". You can use other bases, however. For example,
38+
39+
40+
[source,arduino]
41+
----
42+
String thisString = String(13, HEX);
43+
----
44+
45+
gives you the String "D", which is the hexadecimal representation of the decimal value 13. Or if you prefer binary,
46+
47+
[source,arduino]
48+
----
49+
String thisString = String(13, BIN);
50+
----
51+
52+
gives you the String "1101", which is the binary representation of 13.
2453
[%hardbreaks]
2554

2655

2756
[float]
28-
=== Functions
57+
=== Syntax
58+
[source,arduino]
59+
----
60+
String(val)
61+
String(val, base)
62+
String(val, decimalPlaces)
63+
----
64+
65+
[float]
66+
=== Parameters
67+
`val`: a variable to format as a String - *Allowed data types:* string, char, byte, int, long, unsigned int, unsigned long, float, double
68+
69+
[float]
70+
=== Returns
71+
an instance of the String class.
72+
73+
--
74+
// OVERVIEW SECTION ENDS
75+
76+
77+
78+
// HOW TO USE SECTION STARTS
79+
[#howtouse]
80+
--
81+
82+
[float]
83+
=== Example Code
84+
All of the following are valid declarations for Strings.
85+
[source,arduino]
86+
----
87+
String stringOne = "Hello String"; // using a constant String
88+
String stringOne = String('a'); // converting a constant char into a String
89+
String stringTwo = String("This is a string"); // converting a constant string into a String object
90+
String stringOne = String(stringTwo + " with more"); // concatenating two strings
91+
String stringOne = String(13); // using a constant integer
92+
String stringOne = String(analogRead(0), DEC); // using an int and a base
93+
String stringOne = String(45, HEX); // using an int and a base (hexadecimal)
94+
String stringOne = String(255, BIN); // using an int and a base (binary)
95+
String stringOne = String(millis(), DEC); // using a long and a base
96+
String stringOne = String(5.698, 3); // using a float and the decimal places
97+
----
98+
99+
--
100+
// HOW TO USE SECTION ENDS
101+
102+
103+
// SEE ALSO SECTION
104+
[#see_also]
105+
--
106+
107+
[float]
108+
=== See also
29109

30110
[role="language"]
31111
* #LANGUAGE# link:../string/functions/charat[charAt()]
@@ -65,18 +145,9 @@ For reference, character arrays are referred to as strings with a small s, and i
65145
* #LANGUAGE# link:../string/operators/lessthan[< (less than)]
66146
* #LANGUAGE# link:../string/operators/lessthanorequalto[\<= (less than or equal to)]
67147
* #LANGUAGE# link:../string/operators/differentfrom[!= (different from)]
68-
--
69-
// OVERVIEW SECTION ENDS
70148

71-
72-
// SEE ALSO SECTION STARTS
73-
[#see_also]
74-
--
75-
76-
[float]
77-
=== See also
78-
79-
[role="language"]
149+
[role="example"]
150+
* #EXAMPLE# link: https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[Built-in String Tutorials]
80151

81152
--
82153
// SEE ALSO SECTION ENDS

0 commit comments

Comments
 (0)