| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 |
"http://www.w3.org/TR/html4/strict.dtd"> |
| 3 |
<html> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| 6 |
<title>strscan</title> |
| 7 |
<meta http-equiv="Content-Style-Type" content="text/css"> |
| 8 |
<link rel="stylesheet" href="../../style.css" type="text/css"> |
| 9 |
</head> |
| 10 |
|
| 11 |
<body> |
| 12 |
|
| 13 |
|
| 14 |
<h1>strscan</h1> |
| 15 |
|
| 16 |
<p> |
| 17 |
Searches for substring in string. |
| 18 |
</p> |
| 19 |
|
| 20 |
<h2>Format</h2> |
| 21 |
|
| 22 |
<pre class="macro-syntax"> |
| 23 |
strscan <string> <substring> |
| 24 |
</pre> |
| 25 |
|
| 26 |
<h2>Remarks</h2> |
| 27 |
|
| 28 |
<p> |
| 29 |
Searches for <substring> in <string>.<br> |
| 30 |
If <substring> is found, its position(1-origin) is returned in the system variable "result".<br> |
| 31 |
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. |
| 32 |
</p> |
| 33 |
|
| 34 |
<h2>Example</h2> |
| 35 |
|
| 36 |
<pre class="macro-example"> |
| 37 |
strscan 'tera term' 'term' |
| 38 |
; result = 6 |
| 39 |
int2str valstr result |
| 40 |
messagebox valstr 'result' |
| 41 |
</pre> |
| 42 |
|
| 43 |
<pre class="macro-example"> |
| 44 |
; Converts a hex string to a hexadecimal and binary value |
| 45 |
basenum='0060E3da' |
| 46 |
base=16 |
| 47 |
call base2dec |
| 48 |
int2str sdec decnum |
| 49 |
messagebox sdec 'decnum' |
| 50 |
base=2 |
| 51 |
call dec2base |
| 52 |
messagebox basenum 'basenum' |
| 53 |
end |
| 54 |
|
| 55 |
:dec2base |
| 56 |
basenum='' |
| 57 |
tmp=decnum ;modified so not destructive of decnum |
| 58 |
while tmp > 0 |
| 59 |
strcopy '0123456789ABCDEF' (tmp%base)+1 1 basedig |
| 60 |
strconcat basedig basenum |
| 61 |
basenum=basedig |
| 62 |
tmp=tmp/base |
| 63 |
endwhile |
| 64 |
return |
| 65 |
|
| 66 |
:base2dec |
| 67 |
decnum=0 |
| 68 |
strlen basenum |
| 69 |
len=result |
| 70 |
for i 1 len |
| 71 |
strcopy basenum i 1 basedig |
| 72 |
decnum=decnum*base |
| 73 |
strscan '0123456789ABCDEFabcdef' basedig |
| 74 |
if result>16 result=result-6 ;take care of lower case |
| 75 |
decnum=decnum+result-1 |
| 76 |
next |
| 77 |
return |
| 78 |
</pre> |
| 79 |
|
| 80 |
|
| 81 |
<pre class="macro-example"> |
| 82 |
; Network IP calculation from IP and Subnet mask |
| 83 |
ip='192.168.1.189' |
| 84 |
sn='255.255.255.248' |
| 85 |
bits=0 ;calculate bits & first address in sn |
| 86 |
bitstr='000 128 192 224 240 248 252 254 255' ;lookup table for # bits |
| 87 |
do |
| 88 |
str2int isn sn |
| 89 |
int2str stmp isn |
| 90 |
strscan bitstr stmp ;use lookup table to find bits |
| 91 |
bits=bits+(result-1)/4 |
| 92 |
str2int tmp ip ;find net by bitwise AND of ip and mask |
| 93 |
sprintf2 net '%s%d' net tmp&isn |
| 94 |
strscan sn '.' |
| 95 |
strcopy sn result+1 999 sn |
| 96 |
strscan ip '.' |
| 97 |
strcopy ip result+1 999 ip |
| 98 |
if result>0 strconcat net '.' |
| 99 |
loop while result>0 |
| 100 |
messagebox bits 'bits' |
| 101 |
messagebox net 'net' |
| 102 |
</pre> |
| 103 |
|
| 104 |
|
| 105 |
</body> |
| 106 |
</html> |