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