Replace character at a certain position within a string
POSCHAR(<cString>,<cCharacter|nCharacter>, [<nPosition>]) --> cString
<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>.
The string returned is the <cString> with a <cCharacter|nCharacter> character in the selected position.
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.
. The value returned by this function can be suppressed by implementing CSETREF() to save space in working memory.
. 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"
POSCHAR() is compatible with CT3’s POSCHAR().
Source is pos2.c, library is libct.
POSDEL(), POSINS(), POSREPL(), CSETREF()