Searches for substring in string.
strscan <string> <substring>
Searches for <substring> in <string>.
If <substring> is found, its position(1-origin) is returned in the system variable "result".
If <string> contains more than one occurrence of <substring>, the position of the first one is returned. If <substring> is not found, "result" is set to zero.
strscan 'tera term' 'term' ; result = 6 int2str valstr result messagebox valstr 'result'
; Converts a hex string to a hexadecimal and binary value basenum='0060E3da' base=16 call base2dec int2str sdec decnum messagebox sdec 'decnum' base=2 call dec2base messagebox basenum 'basenum' end :dec2base basenum='' tmp=decnum ;modified so not destructive of decnum while tmp > 0 strcopy '0123456789ABCDEF' (tmp%base)+1 1 basedig strconcat basedig basenum basenum=basedig tmp=tmp/base endwhile return :base2dec decnum=0 strlen basenum len=result for i 1 len strcopy basenum i 1 basedig decnum=decnum*base strscan '0123456789ABCDEFabcdef' basedig if result>16 result=result-6 ;take care of lower case decnum=decnum+result-1 next return
; Network IP calculation from IP and Subnet mask ip='192.168.1.189' sn='255.255.255.248' bits=0 ;calculate bits & first address in sn bitstr='000 128 192 224 240 248 252 254 255' ;lookup table for # bits do str2int isn sn int2str stmp isn strscan bitstr stmp ;use lookup table to find bits bits=bits+(result-1)/4 str2int tmp ip ;find net by bitwise AND of ip and mask sprintf2 net '%s%d' net tmp&isn strscan sn '.' strcopy sn result+1 999 sn strscan ip '.' strcopy ip result+1 999 ip if result>0 strconcat net '.' loop while result>0 messagebox bits 'bits' messagebox net 'net'