Replace characters at a certain position within a string
POSREPL( <[@]cString>, <cReplacement>, [<nStartPosition>] ) -> cString
<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.
POSREPL() returns the modified string.
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>.
. 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.
. 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"
POSREPL() is compatible with CT3’s POSREPL().
Source is pos2.c, library is libct.
POSCHAR(), POSDEL(), POSINS(), CSETREF()