POSREPL()

POSREPL()

Replace characters at a certain position within a string

Syntax

        POSREPL( <[@]cString>, <cReplacement>,
                [<nStartPosition>] ) -> cString

Arguments

<cString> [@] Designates the character string within which the particular characters are replaced.

<cReplacementstring> Designates a sequence of characters that, starting at <nStartPos>, replace a portion of

<cString>. <nStartPos> Designates from which character within <cString> the replacement starts.

Returns

POSREPL() returns the modified string.

Description

When you use POSREPL(), you can replace a range of characters within <cString> with another character string <cReplacementstring>. The new characters are exchanged beginning at <nStartPos>.

Notes

. When the <nStartPos> parameter is not specified, the <cReplacementstring> overwrites the end of the string (see examples). . The return value of this function can be suppressed by implementing CSETREF() to save space in working memory.

Examples

       .  Starting at position 3, replace three characters with "XXX":
              ? POSREPL("ABCDEFG", "XXX", 3)         // "ABXXXFG"
           .  Replace the last LEN(<cReplacementstring>) characters:
              ? POSREPL("ABCDEFG", "XXX")            // "ABCDXXX"
           .  The result can be longer than the character string passed.
              ? POSREPL("ABCDEF", "123", 5)          // "ABCD123"
              ? POSREPL("ABCDEF", "123", 6)          // "ABCDE123"

Compliance

POSREPL() is compatible with CT3’s POSREPL().

Platforms

All

Files

Source is pos2.c, library is libct.

Seealso

POSCHAR(), POSDEL(), POSINS(), CSETREF()

POSINS()

POSINS()

Insert characters at a certain position within a string

Syntax

       POSINS( <cString>, <cInsert>, [<nPosition>] ) 
                -> cString

Arguments

<cString> Designates the character string into which characters are inserted.

<cInsertstring> Designates the new characters that are inserted into <cString>.

<nPosition> Designates the position where the new characters are inserted within <cString>. The default value inserts the characters in front of the last character.

Returns

POSINS() returns the string with the inserted characters.

Description

You can use POSINS() to insert characters into an existing character string. The <cInsertstring> characters are inserted into the <cString> at the location specified by <nPosition>.

Note

. The resulting character string is longer than the original, so this function cannot be called by reference.

Examples

       .  Insert "123" at position 2:
              ? POSINS("abcdefgh", "123", 2)   // "a123bcdefgh"
           .  Insert "123" at position 8:
              ? POSINS("abcdefgh", "123", 8)   // "abcdefg123h"
           .  Give an erroneous position:
              ? POSINS("abcdefgh", "123", 10)  // "abcdefgh"

Compliance

POSINS() is compatible with CT3’s POSINS().

Platforms

All

Files

Source is pos2.c, library is libct.

Seealso

POSCHAR, POSDEL(), POSREPL()

POSDEL()

POSDEL()

Delete characters at a certain position within a string

Syntax

       POSDEL(<cString>,[<nStartPos>],[<nNumber>])
              --> cString

Arguments

<cString> Designates the character string from which the characters are deleted.

<nStartPosition> Designates from which position the deletion begins.

<nNumber> Designates the number of characters to delete.

Returns

The modified string is returned.

Description

This function permits the removal of <nNumber> of characters from <cString>, beginning from <nStartPos>.

Note

. <nStartPos> is optional. If this parameter is not specified, then POSDEL() begins at the end of the <cString> and deletes the specified number (<nNumber>) of characters.

Examples

       .  Delete two characters from a string:
              ? POSDEL("Parameter", 3, 2)         // "Pameter"
           .  Delete the last two characters:
              ? POSDEL("Parameter", , 2)          // "Paramet"

Compliance

POSDEL() is compatible with CT3’s POSDEL().

Platforms

All

Files

Source is pos2.c, library is libct.

Seealso

POSCHAR(), POSINS(), POSREPL()

CSetRef()

CSetRef()

Determine return value of reference sensitive CT3 string functions

Syntax

      CSetRef( [<lNewSwitch>] ) -> lOldSwitch

Arguments

[<lNewSwitch>] .T. -> suppress return value .F. -> do not suppress return value

Returns

lOldSwitch old (if lNewSwitch is a logical value) or current state of the switch

Description

Within the CT3 functions, the following functions do not change the length of a string passed as parameter while transforming this string:

ADDASCII() BLANK() CHARADD() CHARAND() CHARMIRR() CHARNOT() CHAROR() CHARRELREP() CHARREPL() CHARSORT() CHARSWAP() CHARXOR() CRYPT() JUSTLEFT() JUSTRIGHT() POSCHAR() POSREPL() RANGEREPL() REPLALL() REPLLEFT() REPLRIGHT() TOKENLOWER() TOKENUPPER() WORDREPL() WORDSWAP()

Thus, these functions allow to pass the string by reference [@] to the function so that it may not be necessary to return the transformed string. By calling CSetRef (.T.), the above mentioned functions return the value .F. instead of the transformed string if the string is passed by reference to the function. The switch is turned off (.F.) by default.

Compliance

This function is fully CT3 compatible.

Platforms

All

Files

Source is ctstr.c, library is ct3.

Seealso

ADDASCII(), BLANK(), CHARADD(), CHARAND(), CHARMIRR(), CHARNOT(), CHAROR(), CHARRELREP(), CHARREPL(), CHARSORT(), CHARSWAP(), CHARXOR(), CRYPT(), JUSTLEFT(), JUSTRIGHT(), POSCHAR(), POSREPL(), RANGEREPL(), REPLALL(), REPLLEFT(), REPLRIGHT(), TOKENLOWER(), TOKENUPPER(), WORDREPL(), WORDSWAP()

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


CT_POSCHAR

 POSCHAR()
 Replaces an individual character at a particular position within a character
 string
------------------------------------------------------------------------------
 Syntax

     POSCHAR(<cString>,<cCharacter|nCharacter>,
        [<nPosition>]) --> cString

 Arguments

     <cString>  [@]  Designates the character string within which the
     individual character <cCharacter|nCharacter> is substituted.

     <cCharacter|nCharacter>  Designates an individual character or a
     numeric ASCII value from 0 to 255.

     <nPosition>  Designates the position at which the character is
     substituted.  The default value is the last position in <cString>.

 Returns

     The string returned is the <cString> with a <cCharacter|nCharacter>
     character in the selected position.

 Description

     POSCHAR() allows you to replace an individual character within a string
     without having to split the string.  Since this character is only
     substituted at the designated position within <cString>, the string that
     is modified can be passed by reference.

 Note

     .  The value returned by this function can be suppressed by
        implementing CSETREF() to save space in working memory.

 Examples

     .  Substitute a character at position 3:

        ? POSCHAR("ABCDEF", "X", 3)   // "ABXDEF"

     .  Substitute a character in the last position:

        ? POSCHAR("ABCDEF", "X")      // "ABCDEX"

     .  Pass the string by reference:

        CSETREF(.T.)                  // Suppress return value
        cVar  := "ABCDEF"
        POSCHAR(cVar, "X")
        ? cVar                        // "ABCDEX"

See Also: CSETREF()