forked from processing-js/processing-js.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString.html
More file actions
245 lines (101 loc) · 4.74 KB
/
Copy pathString.html
File metadata and controls
245 lines (101 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
---
layout: default
---
<table cellpadding="0" cellspacing="0" border="0" class="ref-item">
<tr class="name-row">
<th scope="row">Name</th>
<td><h3>String</h3></td>
</tr>
<tr class="">
<th scope="row">Examples</th>
<td><div class="example"><pre>String str1 = "CCCP";
char data[] = {'C', 'C', 'C', 'P'};
String str2 = new String(data);
println(str1); // Prints "CCCP" to the console
println(str2); // Prints "CCCP" to the console</pre></div><hr class="noShade" noshade="noshade" size="1" /><div class="example"><pre>// Comparing String objects, see reference below.
String p = "potato";
if (p == "potato") {
println("p == potato, yep."); // this will not print
}
// The correct way to compare two Strings
if (p.equals("potato")) {
println("Yes, the contents of p and potato are the same.");
}</pre></div><hr class="noShade" noshade="noshade" size="1" /><div class="example"><pre>// Use a backslash to include quotes in a String
String quoted = "This one has \"quotes\"";
println(quoted); // This one has "quotes"</pre></div></td>
</tr>
<tr class="">
<th scope="row">Description</th>
<td>A string is a sequence of characters. The class <b>String</b> includes methods for examining individual characters, comparing strings, searching strings, extracting parts of strings, and for converting an entire string uppercase and lowercase. Strings are always defined inside double quotes ("Abc") and characters are always defined inside single quotes('A').
<br /><br />
To compare the contents of two Strings, use the equals() method, as in "if (a.equals(b))", instead of "if (a == b)". A String is an Object, so comparing them with the == operator only compares whether both Strings are stored in the same memory location. Using the equals() method will ensure that the actual contents are compared. (The <a href="http://processing.org/reference/troubleshooting/index.html#strings">troubleshooting</a> reference has a longer explanation.)
<br /><br />
Because a String is defined within quotes, including quotes in a String requires the \ (backslash) character to be used (see the second example above). This is known as an <em>escape sequence</em>. Other escape sequences include \t for the tab character, and \n for new line. A single backslash is indicated by \.
<br /><br />
There are more string methods than those linked from this page. Additional <b>String</b> documentation is located at <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/">http://java.sun.com/j2se/1.4.2/docs/api/</A>.</td>
</tr>
<tr class="">
<th scope="row">Methods</th>
<td><table cellpadding="0" cellspacing="0" border="0">
<tr class="">
<th scope="row"><a href="../reference/String_charAt_">charAt()</a></th>
<td>Returns the character at the specified index</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/String_equals_">equals()</a></th>
<td>Compares a string to a specified object</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/String_indexOf_">indexOf()</a></th>
<td>Returns the index value of the first occurance of a character within the input string</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/String_length_">length()</a></th>
<td>Returns the number of characters in the input string</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/String_substring_">substring()</a></th>
<td>Returns a new string that is part of the input string</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/String_toLowerCase_">toLowerCase()</a></th>
<td>Converts all the characters to lower case</td>
</tr>
<tr class="">
<th scope="row"><a href="../reference/String_toUpperCase_">toUpperCase()</a></th>
<td>Converts all the characters to upper case</td>
</tr>
</table></td>
</tr>
<tr class="">
<th scope="row"><!--*-->Constructor<!--*--></th>
<td><pre>String(<kbd>data</kbd>)
String(<kbd>data</kbd>, <kbd>offset</kbd>, <kbd>length</kbd>)</pre></td>
</tr>
<tr class="">
<th scope="row">Parameters</th>
<td><table cellpadding="0" cellspacing="0" border="0">
<tr class="">
<th scope="row">data</th>
<td>byte[] or char[]: array of bytes to be decoded into characters or array of characters to be combined into a string</td>
</tr>
<tr class="">
<th scope="row">offset</th>
<td>int: index of the first character</td>
</tr>
<tr class="">
<th scope="row">length</th>
<td>int: number of characters</td>
</tr>
</table></td>
</tr>
<tr class="">
<th scope="row">Usage</th>
<td>Web & Application</td>
</tr>
<tr class="">
<th scope="row">Related</th>
<td><a href="../reference/char">char</a>
<br /><a href="../reference/text_">text()</a><br /></td>
</tr>
</table>