Controls << More Strings >> Comments
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.

$result = "Dave" x 4;

The $result will contain the value "DaveDaveDaveDave"

Case operators control the CaSe LeTtErInG.

Case OpEscape EquivalentResult
lc\LAll letters in the string are converted to lower case.
lcfirst\lOnly the first letter in the string is converted to lowercase.
uc\UAll letters in the string are converted to upper case.
ucfirst\uOnly the first letter in the string id converted to uppercase.

$newname1= lc $name1;
$newname2= uc $name2;
print "name1 is $name1. <br>";
print "name2 is $name2. <br>";
print "newname1 is $newname1. <br>";
print "newname2 is $newname2.";

See it in action!
Controls << More Strings >> Comments

Advertise in the banner along the top, Click here!

Valid XHTML 1.0 Transitional Valid CSS! Text Link Ads