Time to re-examine strings. From an earlier tutorial page, its been noted that a string is simply a piece of data that contains letters and may contain numbers as well. Basically though, it is a non-fully-numeric piece of data. This page will show some different abilities you can do with strings.
Connecting or combining strings. JavaScript uses the + (plus) symbol to connect strings. Perl uses the . (period) symbol.
$firstname = "John"; $lastname = "Smith"; $fullname1 = $firstname . $lastname; $fullname2 = $firstname . " " . $lastname; | $fullname1 has the value of "JohnSmith". The script literally combined the two scalar variables together. The second combining script line shows how to put a space in there. $fullname2 has the value of "John Smith".
Strings can have a repetition operator. That is the one string may be repeated (copied and combined) onto itself.
The $result will contain the value "DaveDaveDaveDave"
Case operators control the CaSe LeTtErInG.
| Case Op |
Escape Equivalent |
Result |
| lc |
L |
All letters in the string are converted to lower case. |
| lcfirst |
l |
Only the first letter in the string is converted to lowercase. |
| uc |
U |
All letters in the string are converted to upper case. |
| ucfirst |
u |
Only the first letter in the string id converted to uppercase. |
-----------------
Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.
|