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:
number of characters in string?

 



emelin
stranger

Mar 6, 2001, 7:26 AM

Post #1 of 4 (189 views)
number of characters in string? Can't Post

How do I count the number of characters in a string and then do stuff depending on the number?

I want to do something like:

if number_of_chars_in_$text > 200 {
print char1-char200_of_$text;
print "<a href=allofstring.cgi>cont</a>";
}else{
print $text;
}

(I am reading news items from a file and if the item is too long I want to print out only the first few lines and then link to the entire news item)





japhy
Enthusiast

Mar 6, 2001, 1:19 PM

Post #2 of 4 (187 views)
Re: number of characters in string? [In reply to] Can't Post

length()

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


emelin
stranger

Mar 7, 2001, 2:34 AM

Post #3 of 4 (179 views)
Re: number of characters in string? [In reply to] Can't Post

Thanks, great..!

Now, how do I print out the first, let's say, 300 characters of the string $text???



Jasmine
Administrator / Moderator

Mar 8, 2001, 8:55 AM

Post #4 of 4 (172 views)
Re: number of characters in string? [In reply to] Can't Post


Code
print substr( $text, 0, 300 );


 
 


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

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