develooper Front page | perl.beginners | Postings from April 2010

Extract substring from offset to space or full stop

Thread Previous | Thread Next
From:
Mimi Cafe
Date:
April 18, 2010 06:34
Subject:
Extract substring from offset to space or full stop
Message ID:
4bcb0a3e.5b1ee30a.0cf1.267b@mx.google.com
I used MySQL substr function to extra 100 characters from the result of a
query, but understandably, I don't get what I want.

 

Now I looked at Perl's substr function and it doesn't look like it can help
me achieve what I need to.

 

Let's say I have:

 

$s = "The black cat climbed the green tree";

$substring = substr( $s, 1, 15); # this will return "The black cat c".

 

How can I have this return the whole word climbed rather than the c (i.e. I
need to get "The black cat climbed")? I need to get the remaining characters
from the length till the next white space or end of a phrase.

 

Any other way to overcome this limitation?  How can I use regex here?

 

 

 


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About