1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
2 |
"http://www.w3.org/TR/html4/strict.dtd"> |
"http://www.w3.org/TR/html4/strict.dtd"> |
3 |
<html> |
<html> |
4 |
<head> |
<head> |
5 |
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> |
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> |
6 |
<title>strscan</title> |
<title>strscan</title> |
7 |
<meta http-equiv="Content-Style-Type" content="text/css"> |
<meta http-equiv="Content-Style-Type" content="text/css"> |
8 |
<link rel="stylesheet" href="../../style.css" type="text/css"> |
<link rel="stylesheet" href="../../style.css" type="text/css"> |
9 |
</head> |
</head> |
10 |
|
|
11 |
<body> |
<body> |
12 |
|
|
13 |
|
|
14 |
<h1>strscan</h1> |
<h1>strscan</h1> |
15 |
|
|
16 |
<p> |
<p> |
17 |
部分文字列の位置を返す |
部分文字列の位置を返す |
18 |
</p> |
</p> |
19 |
|
|
20 |
<h2>形式</h2> |
<h2>形式</h2> |
21 |
|
|
22 |
<pre class="macro-syntax"> |
<pre class="macro-syntax"> |
23 |
strscan <string> <substring> |
strscan <string> <substring> |
24 |
</pre> |
</pre> |
25 |
|
|
26 |
<h2>解説</h2> |
<h2>解説</h2> |
27 |
|
|
28 |
<p> |
<p> |
29 |
文字列 <string> の中に、 部分文字列 <substring> が含まれているかどうか調べる。<br> |
文字列 <string> の中に、 部分文字列 <substring> が含まれているかどうか調べる。<br> |
30 |
もし、 <substring> が見つかった場合、その位置(1オリジン)がシステム変数 result に格納される。<br> |
もし、 <substring> が見つかった場合、その位置(1オリジン)がシステム変数 result に格納される。<br> |
31 |
<substring> が複数含まれている場合、最初のものの位置が格納される。もし、 <substring> が見つからなかった場合、 result に0が格納される。 |
<substring> が複数含まれている場合、最初のものの位置が格納される。もし、 <substring> が見つからなかった場合、 result に0が格納される。 |
32 |
</p> |
</p> |
33 |
|
|
34 |
<h2>例</h2> |
<h2>例</h2> |
35 |
|
|
36 |
<pre class="macro-example"> |
<pre class="macro-example"> |
37 |
strscan 'tera term' 'term' |
strscan 'tera term' 'term' |
38 |
; result の値は6 |
; result の値は6 |
39 |
int2str valstr result |
int2str valstr result |
40 |
messagebox valstr 'result' |
messagebox valstr 'result' |
41 |
</pre> |
</pre> |
42 |
|
|
43 |
<pre class="macro-example"> |
<pre class="macro-example"> |
44 |
; 16進文字列を16進および2進へ変換する |
; 16進文字列を16進および2進へ変換する |
45 |
basenum='0060E3da' |
basenum='0060E3da' |
46 |
base=16 |
base=16 |
47 |
call base2dec |
call base2dec |
48 |
int2str sdec decnum |
int2str sdec decnum |
49 |
messagebox sdec 'decnum' |
messagebox sdec 'decnum' |
50 |
base=2 |
base=2 |
51 |
call dec2base |
call dec2base |
52 |
messagebox basenum 'basenum' |
messagebox basenum 'basenum' |
53 |
end |
end |
54 |
|
|
55 |
:dec2base |
:dec2base |
56 |
basenum='' |
basenum='' |
57 |
tmp=decnum ;modified so not destructive of decnum |
tmp=decnum ;modified so not destructive of decnum |
58 |
while tmp>0 |
while tmp>0 |
59 |
strcopy '0123456789ABCDEF' (tmp%base)+1 1 basedig |
strcopy '0123456789ABCDEF' (tmp%base)+1 1 basedig |
60 |
strconcat basedig basenum |
strconcat basedig basenum |
61 |
basenum=basedig |
basenum=basedig |
62 |
tmp=tmp/base |
tmp=tmp/base |
63 |
endwhile |
endwhile |
64 |
return |
return |
65 |
|
|
66 |
:base2dec |
:base2dec |
67 |
decnum=0 |
decnum=0 |
68 |
strlen basenum |
strlen basenum |
69 |
len=result |
len=result |
70 |
for i 1 len |
for i 1 len |
71 |
strcopy basenum i 1 basedig |
strcopy basenum i 1 basedig |
72 |
decnum=decnum*base |
decnum=decnum*base |
73 |
strscan '0123456789ABCDEFabcdef' basedig |
strscan '0123456789ABCDEFabcdef' basedig |
74 |
if result>16 result=result-6 ;take care of lower case |
if result>16 result=result-6 ;take care of lower case |
75 |
decnum=decnum+result-1 |
decnum=decnum+result-1 |
76 |
next |
next |
77 |
return |
return |
78 |
</pre> |
</pre> |
79 |
|
|
80 |
|
|
81 |
<pre class="macro-example"> |
<pre class="macro-example"> |
82 |
; IPアドレスのネットワークアドレスとサブネットマスクを求める |
; IPアドレスのネットワークアドレスとサブネットマスクを求める |
83 |
ip='192.168.1.189' |
ip='192.168.1.189' |
84 |
subnet='255.255.255.248' |
subnet='255.255.255.248' |
85 |
|
|
86 |
sip=subnet ;find number of significant bits |
sip=subnet ;find number of significant bits |
87 |
call ip2bin |
call ip2bin |
88 |
strconcat bip '0' ;ensure there is at least one 0 to find |
strconcat bip '0' ;ensure there is at least one 0 to find |
89 |
strscan bip '0' |
strscan bip '0' |
90 |
bits=result-1 |
bits=result-1 |
91 |
messagebox bits 'bits' |
messagebox bits 'bits' |
92 |
|
|
93 |
sip=ip ;calculate first address in subnet |
sip=ip ;calculate first address in subnet |
94 |
call ip2bin |
call ip2bin |
95 |
strlen bip |
strlen bip |
96 |
strcopy bip 1 bits bip |
strcopy bip 1 bits bip |
97 |
while result-bits>0 |
while result-bits>0 |
98 |
strconcat bip '0' |
strconcat bip '0' |
99 |
result=result-1 |
result=result-1 |
100 |
endwhile |
endwhile |
101 |
call bin2ip |
call bin2ip |
102 |
messagebox sip 'net' |
messagebox sip 'net' |
103 |
end |
end |
104 |
|
|
105 |
:bin2ip ;convert binary ip to decimal number format with dots |
:bin2ip ;convert binary ip to decimal number format with dots |
106 |
sip='' |
sip='' |
107 |
base=2 |
base=2 |
108 |
do |
do |
109 |
strcopy bip 1 8 basenum |
strcopy bip 1 8 basenum |
110 |
call base2dec |
call base2dec |
111 |
int2str sdec decnum |
int2str sdec decnum |
112 |
strconcat sip sdec |
strconcat sip sdec |
113 |
strcopy bip 9 999 bip |
strcopy bip 9 999 bip |
114 |
strlen bip |
strlen bip |
115 |
if result>0 strconcat sip '.' |
if result>0 strconcat sip '.' |
116 |
loop while result>0 |
loop while result>0 |
117 |
return |
return |
118 |
|
|
119 |
:ip2bin ;converts ip number to binary and removes dots |
:ip2bin ;converts ip number to binary and removes dots |
120 |
base=2 |
base=2 |
121 |
bip='' |
bip='' |
122 |
do |
do |
123 |
str2int decnum sip |
str2int decnum sip |
124 |
call dec2base |
call dec2base |
125 |
strlen basenum ;fill in any missing leading zeros |
strlen basenum ;fill in any missing leading zeros |
126 |
strcopy '00000000' 1 8-result stmp |
strcopy '00000000' 1 8-result stmp |
127 |
strconcat bip stmp |
strconcat bip stmp |
128 |
strconcat bip basenum |
strconcat bip basenum |
129 |
strscan sip '.' |
strscan sip '.' |
130 |
strcopy sip result+1 999 sip |
strcopy sip result+1 999 sip |
131 |
loop while result>0 |
loop while result>0 |
132 |
return |
return |
133 |
|
|
134 |
:dec2base ;converts a decimal number to any base |
:dec2base ;converts a decimal number to any base |
135 |
basenum='' |
basenum='' |
136 |
tmp=decnum ;modified so not destructive of decnum |
tmp=decnum ;modified so not destructive of decnum |
137 |
while tmp>0 |
while tmp>0 |
138 |
strcopy '0123456789ABCDEF' (tmp%base)+1 1 basedig |
strcopy '0123456789ABCDEF' (tmp%base)+1 1 basedig |
139 |
strconcat basedig basenum |
strconcat basedig basenum |
140 |
basenum=basedig |
basenum=basedig |
141 |
tmp=tmp/base |
tmp=tmp/base |
142 |
endwhile |
endwhile |
143 |
return |
return |
144 |
|
|
145 |
:base2dec ;converts a number in any base to a decimal number |
:base2dec ;converts a number in any base to a decimal number |
146 |
decnum=0 |
decnum=0 |
147 |
strlen basenum |
strlen basenum |
148 |
len=result |
len=result |
149 |
for tmp 1 len |
for tmp 1 len |
150 |
strcopy basenum tmp 1 basedig |
strcopy basenum tmp 1 basedig |
151 |
strscan '0123456789ABCDEFabcdef' basedig |
strscan '0123456789ABCDEFabcdef' basedig |
152 |
if result=0 break ;if not a num char, stop conversion |
if result=0 break ;if not a num char, stop conversion |
153 |
if result>16 result=result-6 ;take care of lower case |
if result>16 result=result-6 ;take care of lower case |
154 |
decnum=decnum*base |
decnum=decnum*base |
155 |
decnum=decnum+result-1 |
decnum=decnum+result-1 |
156 |
next |
next |
157 |
return |
return |
158 |
</pre> |
</pre> |
159 |
|
|
160 |
|
|
161 |
</body> |
</body> |
162 |
</html> |
</html> |