Re: A way to select first 15 words from a string

From: Stuart (stuart_gibson_at_hotmail.com)
Date: 01/18/04


Date: Sun, 18 Jan 2004 11:17:30 -0000


"paul schroeder" <paulie@hotmail.com> wrote in message
news:400a417b.51741236@News.CIS.DFN.DE...
> Is there a function to select a number of words from a string, say
> first 15?
>
> I can't find one and I thought I should ask before I start wrting some
> script to do it.
>
> If the answer is NO, there is a second question:
>
> If there is no function to do it, do you think it is ok to implode the
> string and then just count out the first 'x' number of words you want?
>
>
> Or is there a better way?
>
> Thanks in advance.

PHP's substr() function does exactly what you need:

Code below is from PHP Manual
(http://uk.php.net/manual/en/function.substr.php)

<?
$rest = substr("abcdef", 1); // returns "bcdef"
$rest = substr("abcdef", 1, 3); // returns "bcd"
$rest = substr("abcdef", 0, 4); // returns "abcd"
$rest = substr("abcdef", 0, 8); // returns "abcdef"
?>

It seems easy enough to get working.



Relevant Pages

  • Re: question re: user account creation script
    ... comma should be a period, and the two string ... Then (write log file entry and move on to next user) ... SubStr As String) As String ... Dim Dest As Long, Src As Long ...
    (microsoft.public.scripting.vbscript)
  • Re: question re: user account creation script
    ... comma should be a period, and the two string ... Then (write log file entry and move on to next user) ... SubStr As String) As String ... Dim Dest As Long, Src As Long ...
    (microsoft.public.scripting.vbscript)
  • Re: grep a string
    ... By occurences I meant positions of SUBSTR in a string.. ... GNU grep prints the byte-offset instead of the ...
    (comp.unix.shell)
  • Re: Bash:Substring Extraction
    ... > portable to older versions of bash? ... Most versions of expr have a substr expression: ... "Shell Scripting Recipes": ... ## return an error if the first character wanted is beyond end of string ...
    (comp.unix.shell)
  • Re: grep a string
    ... > I am trying a find all occurences of a SUBSTR in string ... > will -b option for grep be useful. ... SUBSTR or not. ... > perl script to find all occurences of SUBSTR.. ...
    (comp.unix.shell)

Loading