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: Frequently Asked Questions:
How can I access/change the first N letters of a s

 



Jasmine
Administrator

Jan 19, 2001, 2:49 PM

Post #1 of 1 (2580 views)
How can I access/change the first N letters of a s Can't Post

(From the Perl FAQ)

How can I access/change the first N letters of a string?

There are many ways. If you just want to grab a copy, use substr():

Code
    $first_byte = substr($a, 0, 1);

If you want to modify part of a string, the simplest way is often to use substr() as an lvalue:

Code
    substr($a, 0, 3) = "Tom";

Although those with a pattern matching kind of thought process will likely prefer:

Code
    $a =~ s/^.../Tom/;


 
 


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

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