Harbour All Functions – S

SaveToken

SayScreen

Seconds
Secs

Select

Set

SetAtLike

SetDate

SetKey

SetMode

SetPrec

SetTime

SetTypeahead

Sign

Sin

SinH

Space

Sqrt

Str

StrDiff

StrFormat

StrSwap
StrTran
StrZero
SubStr

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


StrTran()

StrTran()

Translate substring value with a main string

Syntax

      StrTran( <cString>,  <cLocString>,  [<cRepString>],  
               [<nPos>], [<nOccurrences>] ) --> cReturn

Arguments

<cString> The main string to search

<cLocString> The string to locate in the main string

<cRepString> The string to replace the <cLocString>

<nPos> The first occurrence to be replaced

<nOccurrences> Number of occurrence to replace

Returns

<cReturn> Formated string

Description

This function searches for any occurrence of <cLocString> in <cString> and replaces it with <cRepString>. If <cRepString> is not specified, a NULL byte will replace <cLocString>.

If <nPos> is used, its value defines the first occurrence to be replaced. The default value is 1. Additionally, if used, the value of <nOccurrences> tell the function how many occurrences of <cLocString> in <cString> are to the replaced. The default of <nOccurrences> is all occurrences.

Examples

      ? StrTran( "Harbour  Power",  "  ",  " " )   // Harbour Power
      // Harbour Power The future  of  xBase
      ? StrTran( "Harbour  Power  The Future  of  xBase",  "  ",  " " ,  ,  2 )

Compliance

Clipper

Platforms

All(64K)

Files

Libraty is rtl

Seealso

SubStr(), At()

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()

RAt()

RAT()

Searches for a substring from the right side of a string.

Syntax

      RAT( <cSearch>, <cString> ) --> nPos

Arguments

<cSearch> Substring to search for

<cString> Main string

Returns

RAT() return the location of beginning position.

Description

This function searches through <cString> for the first existence of <cSearch>. The search operation is performed from the right side of <cString> to the left. If the function is unable to find any occurrence of <cSearch> in <cString>, the return value is 0.

Examples

      ? 'RAt( "cde", "abcdefgfedcba" ) = ' +;
         RAt( "cde", "abcsefgfedcba" )

Compliance

Clipper

Platforms

All  (64K)

Files

Library is rtl

Seealso

AT(), SUBSTR(), RIGHT()

Left()

LEFT()

Extract the leftmost substring of a character expression

Syntax

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

Arguments

<cString> Main character to be parsed

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

Returns

<cReturn> Substring of evaluation

Description

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

SUBSTR( <cString>, 1, <nLen> )

Examples

      ? LEFT( "HELLO HARBOUR", 5 )    // HELLO

Compliance

Clipper

Platforms

All

Files

Library is rtl

Seealso

SUBSTR(), RIGHT(), AT(), RAT()

hb_RAt()

hb_RAt()

Searches for last occurrence a substring of a string.

Syntax

      hb_RAt( <cSearch>,  <cString>,  [<nStart>],  [<nEnd>]  ) --> nPos

Arguments

<cSearch> Substring to search for

<cString> Main string

<nStart> First position to search in cString, by default 1.

<nEnd> End position to search, by default cString length

Returns

hb_RAt() return the location of beginning position of last occurrence a substring of a string.

Description

This function searches for last occurrence a <cSearch> in <cString>. If the function is unable to find any occurrence of <cSearch> in <cString>, the return value is 0. 3rd and 4th parameters define inclusive range for 2nd parameter on which operation is performed. If 3rd and 4th parameters is not specified, then hb_RAt() is equal to RAt().

Examples

      LOCAL cString
      LOCAL cSearch
      LOCAL i,  y,  r,  nLen

      ? 'hb_RAt( "cde",  "abcdefgfedcba" ) = ',  ;
         hb_RAt( "cde",  "abcdefgfedcba" ) // -> 3

      cString := "acdefcdeedcb"
      cSearch := "cde"
      nLen := Len( cString )
      FOR y := 1 TO nLen
         FOR i := 1 TO nLen
            r := hb_RAt( cSearch,  cString,  y,  i )
            IF r != 0
            ? 'hb_RAt( "' + cSearch + '",  "' + cString + '",  ' + hb_ntos( y ) + ',  ' + hb_ntos( i ) + ' ) = ' + ;
               hb_ntos( r )
            ENDIF
         NEXT
      NEXT

Compliance

Clipper

Platforms

All(64K)

Files

Library is core

Seealso

hb_At(), SubStr(), Right(), RAt()

C5_SUBSTR

 SUBSTR()
 Extract a substring from a character string
------------------------------------------------------------------------------
 Syntax

     SUBSTR(<cString>, <nStart>, [<nCount>]) --> cSubstring

 Arguments

     <cString> is the character string from which to extract a substring.
     It can be up to 65,535 (64K) bytes, the maximum character string size in
     Clipper.

     <nStart> is the starting position in <cString>.  If <nStart> is
     positive, it is relative to the leftmost character in <cString>.  If
     <nStart> is negative, it is relative to the rightmost character in the
     <cString>.

     <nCount> is the number of characters to be extracted.  If omitted,
     the substring begins at <nStart> and continues to the end of the string.
     If <nCount> is greater than the number of characters from <nStart> to
     the end of <cString>, the excess numbers are ignored.

 Returns

     SUBSTR() returns a character string.

 Description

     SUBSTR() is a character function that extracts a substring from another
     character string or memo field.  SUBSTR() is related to the LEFT() and
     RIGHT() functions which extract substrings beginning with leftmost and
     rightmost characters in <cString>, respectively.

     The SUBSTR(), RIGHT(), and LEFT() functions are often used with both the
     AT() and RAT() functions to locate either the first and/or the last
     position of a substring before extracting it.  They are also used to
     display or print only a portion of a character string.

 Examples

     .  These examples extract the first and last name from a
        variable:

        cName:= "Biff Styvesent"
        ? SUBSTR(cName, 1, 4)               // Result: Biff
        ? SUBSTR(cName, 6)                  // Result: Styvesent
        ? SUBSTR(cName, LEN(cName) + 2)     // Result: null string
        ? SUBSTR(cName, -9)                  // Result: Styvesent
        ? SUBSTR(cName, -9, 3)               // Result: Sty

     .  This example uses SUBSTR() with AT() and RAT() to create a
        user-defined function to extract a file name from a file
        specification:

        ? FileBase("C:\PRG\MYFILE.OBJ")      // Result: MYFILE.OBJ

        FUNCTION FileBase( cFile )
           LOCAL nPos
           IF (nPos := RAT("\", cFile)) != 0
              RETURN SUBSTR(cFile, nPos + 1)
           ELSEIF (nPos := AT(":", cFile)) != 0
              RETURN SUBSTR(cFile, nPos + 1)
           ELSE
              RETURN cFile
           ENDIF

 Files   Library is CLIPPER.LIB.


See Also: RAT() RIGHT() STR()

 

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