03-17-2023, 09:19 PM
This does some v____o or something else, no need to check for newlines or anything like that, the business is already expanded if using wildcards!
But try using + instead of * and ~ instead of ? in this example.
But try using + instead of * and ~ instead of ? in this example.
Code: (Select All)
$CONSOLE:ONLY
OPTION _EXPLICIT
REDIM parm(1 TO 1) AS STRING
DIM AS INTEGER v, i
DIM a$, blk$
v = 1
FOR i = 1 TO _COMMANDCOUNT
a$ = COMMAND$(i)
IF INSTR(a$, "+") THEN
ReplaceString2 a$, "+", "*", 0
ELSEIF INSTR(a$, "~") THEN
ReplaceString2 a$, "~", "?", 0
END IF
parm(v) = a$
v = v + 1
REDIM _PRESERVE parm(1 TO v) AS STRING
NEXT
'without "console:only" the user could set this to CHR$(219) for the solid block
blk$ = CHR$(124)
FOR i = 1 TO v - 1
PRINT "Parameter #"; i; " : "; blk$; parm(i); blk$
NEXT
SYSTEM
SUB ReplaceString2 (tx AS STRING, sfind AS STRING, repl AS STRING, numtimes AS _UNSIGNED LONG)
DIM s AS STRING, t AS STRING, goahead AS _BYTE
DIM AS _UNSIGNED LONG ls, count, u
IF (tx = "") OR (sfind = "") OR (sfind = repl) OR (LEN(sfind) > LEN(tx)) THEN EXIT SUB
s = UCASE$(sfind)
t = UCASE$(tx)
ls = LEN(s)
count = 0
goahead = 1
DO
u = INSTR(t, s)
IF u > 0 THEN
tx = LEFT$(tx, u - 1) + repl + MID$(tx, u + ls)
t = UCASE$(tx)
IF numtimes > 0 THEN count = count + 1: IF count >= numtimes THEN goahead = 0
ELSE
goahead = 0
END IF
LOOP WHILE goahead
END SUB