-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathString.xml
More file actions
executable file
·123 lines (98 loc) · 4.08 KB
/
String.xml
File metadata and controls
executable file
·123 lines (98 loc) · 4.08 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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>String</name>
<category>Data</category>
<subcategory>Composite</subcategory>
<usage>Web & Application</usage>
<example>
<image></image>
<code><![CDATA[
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
]]></code>
</example>
<example>
<image></image>
<code><![CDATA[
// Comparing String objects, see reference below.
String p = "potato";
// The correct way to compare two Strings
if (p.equals("potato")) {
println("Yes, the values are the same.");
}
]]></code>
</example>
<example>
<image></image>
<code><![CDATA[
// Use a backslash to include quotes in a String
String quoted = "This one has \"quotes\"";
println(quoted); // This one has "quotes"
]]></code>
</example>
<description><![CDATA[
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 (<b>"Abc"</b>), and characters are always defined inside single quotes (<b>'A'</b>).<br />
<br />
To compare the contents of two Strings, use the <b>equals()</b> method, as in <b>if (a.equals(b))</b>, instead of <b>if (a == b)</b>. A String is an Object, so comparing them with the <b>==</b> operator only compares whether both Strings are stored in the same memory location. Using the <b>equals()</b> method will ensure that the actual contents are compared. (The <a href="https://github.com/processing/processing/wiki/Troubleshooting#why-dont-these-strings-equal">troubleshooting</a> reference has a longer explanation.)<br />
<br />
Because a String is defined between double quotation marks, to include such marks within the String itself you must use the <b>\</b> (backslash) character. (See the third example above.) This is known as an <em>escape sequence</em>. Other escape sequences include <b>\t</b> for the tab character and <b>\n</b> for new line. Because backslash is the escape character, to include a single backslash within a String, you must use two consecutive backslashes, as in: <b>\\</b><br />
<br />
There are more string methods than those linked from this page. Additional documentation is located online in the <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">official Java documentation</a>.
]]></description>
<syntax></syntax>
<method>
<mname>charAt()</mname>
<mdescription>Returns the character at the specified index</mdescription>
</method>
<method>
<mname>equals()</mname>
<mdescription>Compares a string to a specified object</mdescription>
</method>
<method>
<mname>indexOf()</mname>
<mdescription>Returns the index value of the first occurrence of a substring within the input string</mdescription>
</method>
<method>
<mname>length()</mname>
<mdescription>Returns the number of characters in the input string</mdescription>
</method>
<method>
<mname>substring()</mname>
<mdescription>Returns a new string that is part of the input string</mdescription>
</method>
<method>
<mname>toLowerCase()</mname>
<mdescription>Converts all the characters to lower case</mdescription>
</method>
<method>
<mname>toUpperCase()</mname>
<mdescription>Converts all the characters to upper case</mdescription>
</method>
<constructor>
String(<c>data</c>)
String(<c>data</c>, <c>offset</c>, <c>length</c>)
</constructor>
<cparameter>
<clabel>data</clabel>
<cdescription>byte[] or char[]: either an array of bytes to be decoded into characters, or an array of characters to be combined into a string</cdescription>
</cparameter>
<cparameter>
<clabel>offset</clabel>
<cdescription>int: index of the first character</cdescription>
</cparameter>
<cparameter>
<clabel>length</clabel>
<cdescription>int: number of characters</cdescription>
</cparameter>
<returns></returns>
<related>
char
text()
</related>
<availability>1.0</availability>
<type>Object</type>
<partof>PDE</partof>
</root>