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


Space()

Space()

Returns a string of blank spaces

Syntax

      Space( <nSize> ) --> cString

Arguments

<nSize> The length of the string

Returns

<cString> A string containing blank spaces

Description

This function returns a string consisting of <nSize> blank spaces. If the value of <nSize> is 0, a NULL string (“” ) will be returned.

This function is useful to declare the length of a character memory variable.

Examples

      PROCEDURE Main()
         LOCAL cBigString
         LOCAL cFirst
         LOCAL cString := Space( 20 )  // Create an character memory variable
                                       // with length 20
         ? Len( cString )      // 20
         cBigString := Space( 100000 ) // create a memory variable with 100000
                                       // blank spaces
         ? Len( cBigString )
         USE tests NEW
         cFirst := MakeEmpty( 1 )
         ? Len( cFirst )
         RETURN

      FUNCTION MakeEmpty( xField )
         LOCAL nRecord
         LOCAL xRetValue

         IF ! Empty( Alias() )
            nRecord := RecNo()
            dbGoto( 0 )
            IF ValType( xField ) == "C"
               xField := AScan( dbStruct(),  {| aFields | aFields[ 1 ] == Upper( xfield ) } )
            ELSE
               DEFAULT xField TO 0
               IF xField < 1 .OR. xField > FCount()
                  xfield := 0
               ENDIF
            ENDIF
            IF !( xfield == 0 )
               xRetvalue := FieldGet( xfield )
            ENDIF
            dbGoto( nrecord )
         ENDIF
         RETURN xRetvalue

Compliance

Clipper

Platforms

All(64K)

Files

Library is core

Seealso

PadC(), PadL(), PadR(), Replicate()

Replicate()

REPLICATE()

Repeats a single character expression

Syntax

      REPLICATE( <cString>, <nSize> )  --> cReplicateString

Arguments

<cString> Character string to be replicated

<nSize> Number of times to replicate <cString>

Returns

<cReplicateString> A character expression contain the <cString> fill character.

Description

This function returns a string composed of <nSize> repetitions of <cString>. The length of the character string returned by this function is limited to the memory available.

A value of 0 for <nSize> will return a NULL string.

Examples

      ? REPLICATE( "a", 10 )      // aaaaaaaaaa
      ? REPLICATE( "b", 100000 )

Tests

      See Examples

Compliance

Clipper

Platforms

All (64K)

Files

Library is rtl

Seealso

SPACE(), PADC(), PADL(), PADR()

PadR()

PADR()

Right-justifies an expression for a given width

Syntax

      PADR( <xVal>, <nWidth>, <cFill> ) --> cString

Arguments

<xVal> A Number, Character or Date value to pad

<nWidth> Width of output string

<cFill> Character to fill in the string

Returns

<cString> The right-justifies string of <xVal>

Description

This function takes an date, number, or character expression <xVal> and attempt to right-justify it within a string of a given width expressed as <nWidth>. The default character used to pad right side of <xVal> will be an blank space; however, this character may be explicitly specified the value of <cFill>.

If the length of <xVal> is longer then <nWidth>, this function will truncate the string <xVal> from the leftmost side to the length of <nWidth>.

Examples

      ? PADR( "Harbour", 20 )
      ? PADR( 34.5142, 20 )
      ? PADR( Date(), 35 )

Tests

      See examples

Compliance

Clipper

Platforms

All

Files

Library is rtl

Seealso

ALLTRIM(), PADC(), PADL()

PadL()

PADL()

Left-justifies an expression for a given width

Syntax

      PADL( <xVal>, <nWidth>, <cFill> )  --> cString

Arguments

<xVal> An number, Character or date to pad

<nWidth> Width of output string

<cFill> Character to fill in the string

Returns

<cString> The left-justifies string of <xVal>

Description

This function takes an date, number, or character expression <xVal> and attempt to left-justify it within a string of a given width expressed as <nWidth>. The default character used to pad left side of <xVal> will be an blank space; however, this character may be explicitly specified the value of <cFill>.

If the length of <xVal> is longer then <nWidth>, this function will truncate the string <xVal> from the leftmost side to the length of <nWidth>.

Examples

      ? PADL( "Harbour", 20 )
      ? PADL( 34.5142, 20 )
      ? PADL( Date(), 35 )

Tests

      See examples

Compliance

Clipper

Platforms

All

Files

Library is rtl

Seealso

ALLTRIM(), PADC(), PADR()

SP_CENTR

CENTR()

  Short:
  ------
  CENTR() Centers a string in x spaces

  Returns:
  --------
  <cCentered> => String centered

  Syntax:
  -------
  CENTR(cInString,[nSpaces])

  Description:
  ------------
  Centers <cInString> in [nSpaces] spaces

  [nSpaces] spaces is optional. Default is current
  string length

  Examples:
  ---------

   cString := "Superfunction "

   cString := CENTR(cString,20)     //   => "  Superfunction  "

  Notes:
  -------
  In Clipper 5.01, use PADC(), which does the same
  thing and faster. Here for compatibility.

  Source:
  -------
  S_CENTR.PRG

 

C5_PAD

 PAD()
 Pad character, date, and numeric values with a fill character
------------------------------------------------------------------------------
 Syntax

     PADL(<exp>, <nLength>, [<cFillChar>])
        --> cPaddedString
     PADC(<exp>, <nLength>, [<cFillChar>])
        --> cPaddedString
     PADR(<exp>, <nLength>, [<cFillChar>])
        --> cPaddedString

 Arguments

     <exp> is a character, numeric, or date value to be padded with a
     fill character.

     <nLength> is the length of the character string to be returned.

     <cFillChar> is the character with which to pad <exp>.  If not
     specified, the default is a space character.

 Returns

     PADC(), PADL(), and PADR() return the result of <exp> as a character
     string padded with <cFillChar> to a total length of <nLength>.

 Description

     PADC(), PADL(), and PADR() are character functions that pad character,
     date, and numeric values with a fill character to create a new character
     string of a specified length.  PADC() centers <exp> within <nLength>
     adding fill characters to the left and right sides; PADL() adds fill
     characters on the left side; and PADR() adds fill characters on the
     right side.  If the length of <exp> exceeds <nLength>, all of the PAD()
     functions truncate cPaddedString to <nLength>.

     PADC(), PADL(), and PADR() display variable length strings within a
     fixed length area.  They can be used, for instance, to ensure alignment
     with consecutive ?? commands.  Another use is to display text to a fixed-
     width screen area assuring that previous text is completely overwritten.

     PADC(), PADL(), and PADR() are the inverse of the ALLTRIM(), RTRIM(),
     and LTRIM() functions which trim leading and trailing space from
     character strings.

 Examples

     .  This example uses PADR() to format a record number display on
        a status line filling the allocated space:

        IF EOF()
           @ 23, 45 PADR("EOF/" + LTRIM(STR(LASTREC())), 20)
        ELSEIF BOF()
           @ 23, 45 PADR("BOF/" + LTRIM(STR(LASTREC())), 20)
        ELSE
           @ 23, 45 SAY PADR("Record " + LTRIM(STR(RECNO()) ;
                 + "/" + LTRIM(STR(LASTREC())), 20)
        ENDIF

 Files   Library is EXTEND.LIB.

See Also: RTRIM()