String operators
Provides a reference of string operators.
| Syntax | Effect |
|---|---|
| string1 + string2 | Returns a string containing the concatenation of Examples: "Hello," + " world" –> "Hello, world"When the operator + is used to add a string to a nonstring value, the nonstring value is first converted to a string. Examples: "Your age is " + 23 –> "Your age is 23" 23 + " is your age" –> "23 is your age" |
string1 == string2 string1 != string2 |
The operator Examples: "a string" == "a string" –> true "a string" == "another string" –> false "a string" == "A STRING" –> false "a string" != "a string" –> false "a string" != "another string" –> true When the operators == and != are used to compare a string with a number, the string is first converted to a number and the two numbers are compared numerically. Examples: "12" == "+12" –> false 12 == "+12" –> true |
string1 < string2 string1 <= string2 string1 > string2 string1 >= string2 |
The operator Examples: "abc" < "xyz" –> true "a" < "abc" –> true "xyz" < "abc" –> false "abc" < "abc" –> false "abc" > "xyz" –> false "a" > "abc" –> false "xyz" > "abc" –> true Etc. When one of these operators is used to compare a string with a number, the string is first converted to a number and the two numbers are compared numerically. In all other cases, the other argument is first converted to a string. Examples: "10" > "2" –> false 10 > "2" –> true 123 < "2" –> false Hint: Autocasting may cause unexpected behavior. |