ChangeChar
Synopsis
nreplace = ChangeChar(string, len, fchar, rchar)
D0 A0 D0 D1 D2C Prototype
ULONG ChangeChar(STRPTR string, ULONG len, ULONG fchar, ULONG rchar);Description
Searches for a character in a byte sequence, and when found, replaces it, continuing until it encounters the ASCII code 0 (null terminator). This is true if no length was passed in len; otherwise, the scan can be forced for a specific number of bytes.
Inputs
- string — Pointer to a string, not necessarily null-terminated.
- len — Number of characters to check. If NULL, the check ends when the ASCII code 0 is found.
- fchar — ASCII code to find. THIS MUST BE NON-ZERO IF
lenis NULL. - rchar — ASCII code to substitute.
Result
- nreplace — Number of replacements made.
Notes
If you set fchar to ASCII code 0 (zero) and at the same time set len to NULL, the command will not perform any replacements. In this case, you must either provide a length or use FilterChars() first.
See Also
Implementation
The original 68020 assembly implementation:
; (26-Nov-1994) --- ChangeChar()
_LVOChangeChar
movem.l d0-d5/a0,-(sp)
moveq #0,d5
move.w d0,d4
subq.w #1,d4
CC_CMPtwo
tst.w d0
bne.s CC_CMP
CC_TestZero
moveq #1,d4
tst.b (a0)
beq.s CC_Exit
CC_CMP move.b (a0),d3
cmp.b d1,d3
bne.s CC_NoFind
move.b d2,(a0)
addq.w #1,d5
CC_NoFind
addq.w #1,a0
dbf d4,CC_CMPtwo
CC_Exit move.l d5,(sp)
movem.l (sp)+,d0-d5/a0
move.l d0,d0
rts