Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fast replace$() function
#3
this is the function i use.  see if you could figure out why.

otherwise yes, this too is flawed, but in a different way.

Code: (Select All)
SUB ReplaceString3 (tx AS STRING, sfind AS STRING, repl AS STRING, numtimes AS _UNSIGNED LONG)
    DIM AS STRING s, t, searc, replac
    DIM AS _UNSIGNED LONG ls, count, u, j
    DIM AS _BYTE goahead
    IF (tx = "") OR (sfind = "") OR (sfind = repl) OR (LEN(sfind) > LEN(tx)) THEN EXIT SUB
    FOR j = 1 TO 2
        IF j = 1 THEN
            searc = sfind
            replac = CHR$(255)
        ELSE
            searc = CHR$(255)
            replac = repl
        END IF
        s = UCASE$(searc)
        t = UCASE$(tx)
        ls = LEN(s)
        count = 0
        goahead = 1
        DO
            u = INSTR(t, s)
            IF u > 0 THEN
                tx = LEFT$(tx, u - 1) + replac + 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
    NEXT
END SUB
Reply


Messages In This Thread
Fast replace$() function - by mdijkens - 04-15-2025, 10:00 AM
RE: Fast replace$() function - by bplus - 04-15-2025, 10:34 AM
RE: Fast replace$() function - by hsiangch_ong - 04-18-2025, 06:04 PM
RE: Fast replace$() function - by mdijkens - 04-18-2025, 07:31 PM
RE: Fast replace$() function - by SMcNeill - 04-18-2025, 08:29 PM
RE: Fast replace$() function - by mdijkens - 04-18-2025, 09:08 PM
RE: Fast replace$() function - by SMcNeill - 04-19-2025, 08:48 AM
RE: Fast replace$() function - by madscijr - 04-18-2025, 11:07 PM
RE: Fast replace$() function - by mdijkens - 04-19-2025, 10:19 AM
RE: Fast replace$() function - by hsiangch_ong - 04-19-2025, 05:23 PM
RE: Fast replace$() function - by mdijkens - 04-19-2025, 06:27 PM



Users browsing this thread: 2 Guest(s)