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

POSCHAR()

POSCHAR()

Replace character at a certain position within a 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"

Compliance

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

Platforms

All

Files

Source is pos2.c, library is libct.

Seealso

POSDEL(), POSINS(), POSREPL(), CSETREF()

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_POSDEL

 POSDEL()
 Deletes characters at a particular position in a string
------------------------------------------------------------------------------
 Syntax

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

 Arguments

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

     <nStartPos>  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"

See Also: POSINS() POSRANGE()

 

Tools – String Manipulations

Introduction 
ADDASCII()   Adds a value to each ASCII code in a string
AFTERATNUM() Returns remainder of a string after nth appearance of sequence
ASCIISUM()   Finds sum of the ASCII values of all the characters of a string
ASCPOS()     Determines ASCII value of a character at a position in a string
ATADJUST()   Adjusts the beginning position of a sequence within a string
ATNUM()      Determines the starting position of a sequence within a string
ATREPL()     Searches for a sequence within a string and replaces it
ATTOKEN()    Finds the position of a token within a string
BEFORATNUM() Returns string segment before the nth occurrence of a sequence
CENTER()     Centers a string using pad characters
CHARADD()    Adds the corresponding ASCII codes of two strings
CHARAND()    Links corresponding ASCII codes of paired strings with AND
CHAREVEN()   Returns characters in the even positions of a string
CHARLIST()   Lists each character in a string
CHARMIRR()   Mirrors characters within a string
CHARMIX()    Mixes two strings together
CHARNOLIST() Lists the characters that do not appear in a string
CHARNOT()    Complements each character in a string
CHARODD()    Returns characters in the odd positions of a string
CHARONE()    Reduces adjoining duplicate characters in string to 1 character
CHARONLY()   Determines the common denominator between two strings
CHAROR()     Joins the corresponding ASCII code of paired strings with OR
CHARPACK()   Compresses (packs) a string
CHARRELA()   Correlates the character positions in paired strings
CHARRELREP() Replaces characters in a string depending on their correlation
CHARREM()    Removes particular characters from a string
CHARREPL()   Replaces certain characters with others
CHARSORT()   Sorts sequences within a string
CHARSPREAD() Expands a string at the tokens
CHARSWAP()   Exchanges all adjoining characters in a string
CHARUNPACK() Decompresses (unpacks) a string
CHARXOR()    Joins ASCII codes of paired strings with exclusive OR operation
CHECKSUM()   Calculates the checksum for a character string (algorithm)
COUNTLEFT()  Counts a particular character at the beginning of a string
COUNTRIGHT() Counts a particular character at the end of a string
CRYPT()      Encrypts and decrypts a string
CSETATMUPA() Determines setting of the multi-pass mode for ATXXX() functions
CSETREF()    Determines whether reference sensitive functions return a value
EXPAND()     Expands a string by inserting characters
JUSTLEFT()   Moves characters from the beginning to the end of a string
JUSTRIGHT()  Moves characters from the end of a string to the beginning
LIKE()       Compares character strings using wildcard characters
LTOC()       Converts a logical value into a character
MAXLINE()    Finds the longest line within a string
NUMAT()      Counts the number of occurrences of a sequence within a string
NUMLINE()    Determines the number of lines required for string output
NUMTOKEN()   Determines the number of tokens in a string
PADLEFT()    Pads a string on the left to a particular length
PADRIGHT()   Pads a string on the right to a particular length
POSALPHA()   Determines position of first alphabetic character in a string
POSCHAR()    Replaces individual character at particular position in string
POSDEL()     Deletes characters at a particular position in a string
POSDIFF()    Finds the first position from which two strings differ
POSEQUAL()   Finds the first position at which two strings are the same
POSINS()     Inserts characters at a particular position within a string
POSLOWER()   Finds the position of the first lower case alphabetic character
POSRANGE()   Determines position of first character in an ASCII code range
POSREPL()    Replaces one or more characters from a certain position
POSUPPER()   Finds the position of the first uppercase, alphabetic character
RANGEREM()   Deletes characters that are within a specified ASCII code range
RANGEREPL()  Replaces characters within a specified ASCII code range
REMALL()     Removes characters from the beginning and end of a string
REMLEFT()    Removes particular characters from the beginning of a string
REMRIGHT()   Removes particular characters at the end of a string
REPLALL()    Exchanges characters at the beginning and end of a string
REPLLEFT()   Exchanges particular characters at the beginning of a string
REPLRIGHT()  Exchanges particular characters at the end of a string
RESTTOKEN()  Recreates an incremental tokenizer environment
SAVETOKEN()  Saves the incremental tokenizer environment to a variable
SETATLIKE()  Provides an additional search mode for all AT functions
STRDIFF()    Finds similarity between two strings (Levenshtein Distance)
STRSWAP()    Interchanges two strings
TABEXPAND()  Converts tabs to spaces
TABPACK()    Converts spaces in tabs
TOKEN()      Selects the nth token from a string
TOKENAT()    Determines the most recent TOKENNEXT() position within a string
TOKENEND()   Determines if more tokens are available in TOKENNEXT()
TOKENINIT()  Initializes a string for TOKENNEXT()
TOKENLOWER() Converts initial alphabetic character of a token into lowercase
TOKENNEXT()  Provides an incremental tokenizer
TOKENSEP()   Provides separator before/after most recently retrieved TOKEN()
TOKENUPPER() Converts the initial letter of a token into upper case
VALPOS()     Determines numerical value of character at particular position
WORDONE()    Reduces multiple appearances of double characters to one
WORDONLY()   Finds common denominator of 2 strings on double character basis
WORDREPL()   Replaces particular double characters with others
WORDSWAP()   Exchanges double characters lying beside each other in a string
WORDTOCHAR() Exchanges double characters for individual ones