Harbour All Function – L

L2Bin
LanguageAndNationMSG

LastDayOM
LastKey
LastRec
Left
Len
Log

Log10
Lower
LTrim

LUpdate

String Functions

AddASCII

AfterAtNum

AllTrim
Asc

ASCIISum

ASCPos
At

AtAdjust

AtNum
AtRepl
AtToken

BeforAtNum

Chr

CharAdd
CharAnd
CharEven
CharHist
CharList
CharMirr
CharMix
CharNoList
CharNot
CharOdd
CharOne
CharOnly
CharOr
CharPix
CharRela
CharRelRep
CharRem
CharRepl
CharRLL
CharRLR
CharSHL
CharSHR
CharSList
CharSort
CharSub
CharSwap
CharWin
CharXOR

CountLeft
CountRight
Descend
Empty
hb_At
hb_RAt
hb_ValToStr
IsAlpha
IsDigit
IsLower
IsUpper

JustLeft
JustRight

Left
Len
Lower
LTrim

NumAt
NumToken
PadLeft
PadRight

PadC
PadL
PadR

POSALPHA
POSCHAR
POSDEL
POSDIFF
POSEQUAL
POSINS
POSLOWER
POSRANGE
POSREPL
POSUPPER

RangeRem
RangeRepl

RAt

RemAll

RemLeft
RemRight
ReplAll

Replicate

ReplLeft

ReplRight

RestToken

Right
RTrim

SaveToken

SetAtLike
Space
Str

StrDiff

StrFormat

StrSwap

StrTran
StrZero
SubStr

TabExpand
TabPack

Token

TokenAt
TokenEnd
TokenExit
TokenInit
TokenLower
TokenNext
TokenNum
TokenSep
TokenUpper

Transform
Trim
Upper
Val

ValPos
WordOne
WordOnly
WordRem
WordRepl
WordSwap

WordToChar


SubStr()

SubStr()

Returns a substring from a main string

Syntax

      SubStr( <cString>,  <nStart>,  [<nLen>] ) --> cReturn

Arguments

<cString> Character expression to be parsed

<nStart> Start position

<nLen> Number of characters to return

Returns

<cReturn> Substring of evaluation

Description

This functions returns a character string formed from <cString>, starting at the position of <nStart> and continuing on for a length of <nLen> characters. If <nLen> is not specified, the value will be all remaining characters from the position of <nStart>.

The value of <nStart> may be negative. If it is, the direction of operation is reversed from a default of left-to-right to right-to-left for the number of characters specified in <nStart>. If the number of characters from <nStart> to the end of the string is less than <nLen> the rest are ignored.

Examples

      ? SubStr( "HELLO HARBOUR" ,   7,  4 )      // HARB
      ? SubStr( "HELLO HARBOUR" ,  -3,  3 )      // OUR
      ? SubStr( "HELLO HARBOUR" ,   7    )      // HARBOUR

Compliance

Clipper

Platforms

All(64K)

Files

Library is core

Seealso

Left(), At(), Right()

Right()

RIGHT()

Extract the rightmost substring of a character expression

Syntax

      RIGHT( <cString>, <nLen> ) --> cReturn

Arguments

<cString> Character expression to be parsed

<nLen> Number of bytes to return beginning at the rightmost position

Returns

<cReturn> Substring of evaluation

Description

This functions returns the rightmost <nLen> characters of <cString>. It is equivalent to the following expressions:

SUBSTR( <cString>, – <nLen> )

SUBSTR( <cString>, LEN( <cString> ) – <nLen> + 1, <nLen> )

Examples

      ? RIGHT( "HELLO HARBOUR", 5 )     // RBOUR

Compliance

Clipper

Platforms

All

Files

Library is rtl

Seealso

SUBSTR(), LEFT(), AT(), RAT()

SP_ALLBUT

ALLBUT()

  Short:
  ------
  ALLBUT() Returns all but last x characters

  Returns:
  --------
  <cAllBut> => All but last n characters

  Syntax:
  -------
  ALLBUT(cInString,nAllBut)

  Description:
  ------------
  Returns all but the rightmost <nAllbutt> letters of
  <cInString>

  Examples:
  ---------

   string := "SUPERFUNCTION"
   string := ALLBUT(string,8)    //  => returns  "SUPER"

  Notes:
  -------
  Useful when you don't know the length of a string in
  order to take left(x) characters.

  Source:
  -------
  S_ALLBUT.PRG

 

C5_LEFT

 LEFT()
 Extract a substring beginning with the first character in a string
------------------------------------------------------------------------------
 Syntax

     LEFT(<cString>, <nCount>) --> cSubString

 Arguments

     <cString> is a character string from which to extract characters.
     The maximum size of <cString> is 65,535 (64K) bytes.

     <nCount> is the number of characters to extract.

 Returns

     LEFT() returns the leftmost <nCount> characters of <cString> as a
     character string.  If <nCount> is negative or zero, LEFT() returns a
     null string ("").  If <nCount> is larger than the length of the
     character string, LEFT() returns the entire string.

 Description

     LEFT() is a character function that returns a substring of a specified
     character string.  It is the same as SUBSTR(<cString>, 1, <nCount>).
     LEFT() is also like RIGHT(), which returns a substring beginning with
     the last character in a string.

     LEFT(), RIGHT(), and SUBSTR() are often used with both the AT() and
     RAT() functions to locate the first and/or the last position of a
     substring before extracting it.

 Examples

     .  This example extracts the first three characters from the left
        of the target string:

        ? LEFT("ABCDEF", 3)                  // Result: ABC

     .  This example extracts a substring from the beginning of a
        string up to the first occurrence of a comma:

        LOCAL cName := "James, William"
        ? LEFT(cName, AT(",", cName) - 1)   // Result: James

 Files   Library is CLIPPER.LIB.

See Also: AT() LTRIM() RAT() RIGHT() RTRIM() STUFF() SUBSTR()



First + Last words in a string

/*
First + Last words in a string

*/
PROCEDURE Main()
   CLS
   ?
   ? "First + Last words in a string"
   ?

   cUpString := "Miguel Cervantes de Saavedra"

   ? "Up String :", cUpString
   ?

   cNewString := LEFT( cUpString, AT( " ", cUpString ) )+; // First word
            SUBSTR( cUpString, RAT( " ", cUpString ) + 1 ) // Last word 

   ?
   ? "Method one ( manual ) :", cNewString // Miguel Saavedra

   aWords := HB_ATOKENS( cUpString )
   cNewString := aWords[ 1 ] + " " + ; // First word
                 ATAIL( aWords )       // Last word
   ?
   ? "Method two ( ATOKENS() ) :", cNewString // Miguel Saavedra

   *
   * TOKEN() function require libhbct
   *
   cNewString := TOKEN( cUpString,,1 ) + " " + ; // First word
                 TOKEN( cUpString )              // Last word 

   ?
   ? "Method three ( TOKEN() ) :", cNewString // Miguel Saavedra

   @ MAXROW(), 0
   WAIT "EOF FLWs.prg"

RETURN // FLWs.Main()

FLWs