CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
String Manipulation

 



klgan
stranger

Oct 21, 2001, 7:33 PM

Post #1 of 3 (383 views)
String Manipulation Can't Post

Hi
Can anyone help me on this?

How do I access each individual character of a string, eg "This is Perl Programming". Can this string be broken up into an array of characters?

Help appreciated! Thanks.



mhx
Enthusiast / Moderator

Oct 21, 2001, 9:39 PM

Post #2 of 3 (380 views)
Re: String Manipulation [In reply to] Can't Post

You can access individual characters of a string using the substr function:

Code
#!/bin/perl -w 

$string = "This is Perl Programming";

if( substr( $string, 8, 1 ) eq 'P' ) {
print "It's the beginning of Perl!\n";
}

If you really need an array of characters, use a regular expression:

Code
#!/bin/perl -w 

$string = "This is Perl Programming";
@a = $string =~ /(.)/g;

print join(', ', @a), "\n";

Hope this helps.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"



klgan
stranger

Oct 22, 2001, 1:10 AM

Post #3 of 3 (379 views)
Re: String Manipulation [In reply to] Can't Post

Hi Marcus

Thanks a lot for the guide. It works great for me!


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives