MID$ in Spin?
Moskog
Posts: 556
Can anyone help me with a MID$ function in spin?
Example: (Two strings: date and mm)
date = "09:10:12" (Known value)
mm = MID$ (date,4,2) .. that will return "10", how do I do that?
Then how would be the simplest way to convert the string mm into a decimal value?
Example: (Two strings: date and mm)
date = "09:10:12" (Known value)
mm = MID$ (date,4,2) .. that will return "10", how do I do that?
Then how would be the simplest way to convert the string mm into a decimal value?

Comments
VAR byte hh[3], mm[3], ss[3] byte hour, minute, second PUB start | time time := string("12:45:13") 'Break string into pieces: midstr(@hh, time, 0, 2) midstr(@mm, time, 3, 2) midstr(@ss, time, 6, 2) 'Or, more simply, do this to get actual values: hour := str2val(time) minute := str2val(time + 3) second := str2val(time + 6) PUB midstr(destaddr, srcaddr, first, len) 'Copy part of a string to another string. bytemove(destaddr, srcaddr + first, len) byte[destaddr + len]~ PUB str2val(straddr) | c 'Accumulate a value from string as long as processing actual digits. repeat while (c := byte[straddr++]) => "0" and c =< "9" result := result * 10 + c - "0"The first method just breaks up the string without doing a conversion; the second, skips the breakup altogether and just does the conversion to numbers.
-Phil
I really do appreciate you being so helpful when I'm stuck in difficulties!