Extracting parts of a string


#1

cant seem to find a function to extract part of a string:
example, I have a tag in t$: Humidity:RR1
I can find the pos of the ‘:’ with the INSTR, but how do I extract the two parts separated by the ‘:’

need to break out the two parts. I was looking for a SUBSTR type function.

t1$ = ‘Humidity’
t2$ = ‘RR1’


#2

Hi @wizardontherun

There unfortunately doesn’t exist a substring function in BASIC. In your scenario you can do:

t$ = "Humidity:RR1"
i% = INSTR 1, t$, ":"
s$ = t$(1 TO (i% - 1))
p$ = t$((i% + 1) TO LEN(t$))

REM This will print:
REM s$ = Humidity
REM p$ = RR1

The reason we can do this is because you know of a specific character in the text. So basically we find the character and track the index, we then take the “substring” of the main string by taking the chars from position X to the index of your known character.