String Functions

Domain Hosting image
Web Hosting
Dedicated server
ssl certificate
Web Design image
Email

The first set of functions that we'll look at are those that deal with strings. Those functions let you determine a string's length, search for a sub string, and change the case of the characters in the string, among other things. chomp(STRING) OR chomp(ARRAY) - Uses the value of the $/ special variable to remove endings from STRING or each element of ARRAY. The line ending is only removed if it matches the current value of $/.

Eg.:
$a = "Hello PENTASOFT\n";
$b ="Hello students";
chomp($a);
chomp($b);
will remove the newline from the variable $a and does not remove anything from $b.

chop(STRING) OR chop(ARRAY) - Removes the last character from a string or the last character from every element in an array. The last character chopped is returned.

Eg.:
$a = "Hello PENTASOFT"
chop($a); will remove the last character T from the variable $a.

chr(NUMBER) -

Returns the character represented by NUMBER in the ASCII table.

Eg.:
$a = chr(65);
print "the value in \$a is $a\n";
will display : the value in $a is A

index(STRING, SUBSTRING, POSITION) -

Returns the position of the first occurrence of SUBSTRING in STRING at or after POSITION. If you don't specify POSITION, the search starts at the beginning of STRING. If the search substring is not found it will return -1.

Eg,:
print index(" PENTASOFT", "E");
will display 1.

join(STRING, ARRAY) - Returns a string that consists of all of the elements of ARRAY joined together by STRING.

Eg.:
@a = (What', 'is', 'going', 'on');
print join("-" ",&a);
will display: What-is-going-on

Ic(STRING) Return " string with every letter of STRING in lowercase.
Eg.:
$a="Capital";
print lc($a);
will display: capital

lcfirst(STRING) - Returns a string with the first letter of STRING in lowercase.

Eg.:
$a="'CaplTal";
print lcfirst($a);
will display: caplTal

length(STRING) - Returns the length of STRING.
Eg.: $a="Capital";
print length($a);
will display: 7

rindex(STRING, SUBSTRING, POSITION) - Returns the position of the last occurrence of SUBSTRING in STRING at or after POSITION.If you don't specify POSITION, the search starts at the end of STRING.

Eg.:
print rindex("Will call","ll");
will display: 7

split(PATTERN, STRING, LIMIT) - Breaks up a string based on some delimiter. In an array context, it returns a list of the things that were found. In a scalar context, it returns the number of things found.

Eg.:
$a = "this\tis\tpentasoft"
@b = split(^t/,$a); print @b;
will display: thisispentasoft

substr(STRING, OFFSET, LENGTH) - Returns a portion of STRING as determined by the OFFSET and LENGTH parameters, If LENGTH is not specified, then everything from OFFSET to the end of STRING is returned. A negative OFFSET can be used to start from the right side of STRING.

Eg.:
$a = substr("This is a small string",5,4);
print $a;
will display: is a

uc(STRING) - Returns a string with every letter of STRING in uppercase.

Eg.:
$a = "Abcd";
print uc($a);
will display: ABCD

ucfirst(STRING) - Returns a string with the first letter of STRING in uppercase.

Eg.;
$a = "abCD";
print ucfirst($a);
will display: AbCD



Domain Name Search

www.


Copyright (C) 2007. Web Domain design hosting. All rights reserved.