Hi Colin,
Alas, I too have frequently found the wording and examples in these manuals to be badly worded, outdated, confusing, and sometimes just plain wrong. Over the years I have found it quicker to ignore some of these library routines and just write my own, which (a.) I understand, and (b.) do exactly what I want. Much quicker than trying to sort through all the library source code to locate/understand/correct what the deal is.
The probability of a Manual Correction being generated is quite small, I think.
I think my rant is the same as yours. Anyway, here is my take on this particular issue.
The Gold manual, page 444, (aka PDF page 475) gives the definition of the NREPCHAR$ Function as:
NREPCHAR$ Function
Library: STRLIB.TRC
Syntax: NREPCHAR$ (strex, strex, strex)
Usage: LET a$ = NREPCHAR$ (text$, oldchars$, new$)
Summary: Returns the value of text$ with all characters not appearing in oldchars$ replaced by the
value of new$.
Details: The NREPCHAR$ function maps all characters which are not members of a character set to
a single string. It returns the value of text$ after having replaced any occurrences of
characters not appearing in the value of oldchars$ with the value of new$.
Example: The following program:
LIBRARY “STRLIB.TRC”
DECLARE DEF Digits$, NRepChar$
OPEN #1: NAME “InFile”
LET chars$ = Digits$
DO WHILE MORE #1
LINE INPUT #1: line$
PRINT NRepChar$(line$, chars$, “ “)
LOOP
GET KEY k
END
lists the contents of a text file named INFILE, replacing all characters which are not digits
with spaces.
Exceptions: None
See also: REPCHAR$, MAPCHAR$, DELCHAR$, KEEPCHAR$, PLUGCHAR$,NPLUGCHAR$
[My comment here is: why complicate the example with all the "opening a file" garbage? And why not use the same argument names as in the definition?]
===========
In TB Silver "TBlibs\", the file "strlib.tru" gives the definition of NPlugChar$ as:
DEF NPlugChar$(text$,chars$,template$)
DECLARE DEF RepStr$
FOR p = Len(text$) to 1 step -1
LET p = Ncposr(text$,chars$,p)
IF p=0 then
LET NPlugChar$ = text$
EXIT DEF
END IF
LET text$[p:p] = RepStr$(template$,"#1",text$[p:p]) ! (text$. oldchars$, new$)
NEXT p
LET NplugChar$ = text$
END DEF
----------------------
Here is my example:
! my example program:
option nolet
LIBRARY "strlib.trc"
DECLARE DEF NPlugChar$
text$="sagsfgrg,123drg 678/678 ijsdnbsjddn123oskghogf$345@vfr"
chars$="0123456789"
template$=chr$(183) ! "·"
y$=NPlugChar$(text$,chars$,template$)
set cursor 3,1
print, "text$ was: """&text$&""""
print
print, "now it is: """;y$&""""
print
print, "but text$ is still: """&text$&""""
get key zz
END
=============
This does work, but it took me a while to root out the source and see how it actually works. I ran it on TB Gold 6.007. It works on any TB version.
What particular problem had you had with this function?
Anyway, I hope this helps. Feel free to use email if you want.
Regards,
Mike C.