Useful function for your toolbox

Started by MrBcx, July 31, 2024, 01:55:09 PM

Previous topic - Next topic

Quin

Saw this months back, but didn't need it until today. You're right though MrBcx, incredibly powerful and useful. Thanks loads for this!

MrBcx

This is a slight variation of an internal function that BCX uses. 

I personally find it very useful. 

If you find yourself regularly parsing strings, you will likely find it useful too.



'******************************************************************************
' Executes a CASE-INSENSITIVE search for NON-QUOTED MatchStr$ inside MainStr$
'******************************************************************************
' If MatchStr$ is found NOT QUOTED inside MainStr$, FINDNQ() returns TRUE
' If MatchStr$ is found QUOTED inside MainStr$, FINDNQ() returns FALSE
' Everything else returns FALSE
'******************************************************************************

FUNCTION FINDNQ (MainStr$, MatchStr$) AS LONG
    DIM RAW mi
    DIM RAW a AS PCHAR
    mi = 0
    a = MainStr
    DO WHILE MatchStr[mi]
        IF *a = 34 THEN
            mi = 0
            DO WHILE *(++a) <> 34
                IF *a = 0 THEN FUNCTION = 0
            LOOP
        END IF
        IF a[mi] = 0 THEN FUNCTION = 0                   
        IF (a[mi] BOR 32) <> (MatchStr[mi] BOR 32) THEN   
            INCR a
            mi = (-1)
        END IF
        INCR mi
    LOOP
    FUNCTION = TRUE   
END FUNCTION