Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String handeling

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How can I make an test on the first character in a string. I want to test if the string starts with an a for excample.
 

Either of these would do it. $string is the string you are testing...

$string =~ /^a/ # regular expression

substr($string, 0, 1) eq 'a' # substring containing first character
 
Or you could use the alternate "start of string" assertion:
Code:
if ( $string =~ /\Aa/ )
I prefer to use \A instead of ^ (and \Z instead of $) because they're easier to remember and look more like what they do. Just a matter of preference.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top