Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Contents of /trunk/doc/en/html/macro/command/strscan.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3227 - (show annotations) (download) (as text)
Tue Mar 24 15:10:33 2009 UTC (15 years, 1 month ago) by maya
File MIME type: text/html
File size: 3675 byte(s)
CVS から SVN へ移行: 改行コードを LF から CR+LF へ変換
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 &lt;string&gt; &lt;substring&gt;
24 </pre>
25
26 <h2>Remarks</h2>
27
28 <p>
29 Searches for &lt;substring&gt; in &lt;string&gt;.<br>
30 If &lt;substring&gt; is found, its position(1-origin) is returned in the system variable "result".<br>
31 If &lt;string&gt; contains more than one occurrence of &lt;substring&gt;, the position of the first one is returned. If &lt;substring&gt; 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 subnet='255.255.255.248'
85
86 sip=subnet ;find number of significant bits
87 call ip2bin
88 strconcat bip '0' ;ensure there is at least one 0 to find
89 strscan bip '0'
90 bits=result-1
91 messagebox bits 'bits'
92
93 sip=ip ;calculate first address in subnet
94 call ip2bin
95 strlen bip
96 strcopy bip 1 bits bip
97 while result-bits>0
98 strconcat bip '0'
99 result=result-1
100 endwhile
101 call bin2ip
102 messagebox sip 'net'
103 end
104
105 :bin2ip ;convert binary ip to decimal number format with dots
106 sip=''
107 base=2
108 do
109 strcopy bip 1 8 basenum
110 call base2dec
111 int2str sdec decnum
112 strconcat sip sdec
113 strcopy bip 9 999 bip
114 strlen bip
115 if result>0 strconcat sip '.'
116 loop while result>0
117 return
118
119 :ip2bin ;converts ip number to binary and removes dots
120 base=2
121 bip=''
122 do
123 str2int decnum sip
124 call dec2base
125 strlen basenum ;fill in any missing leading zeros
126 strcopy '00000000' 1 8-result stmp
127 strconcat bip stmp
128 strconcat bip basenum
129 strscan sip '.'
130 strcopy sip result+1 999 sip
131 loop while result>0
132 return
133
134 :dec2base ;converts a decimal number to any base
135 basenum=''
136 tmp=decnum ;modified so not destructive of decnum
137 while tmp>0
138 strcopy '0123456789ABCDEF' (tmp%base)+1 1 basedig
139 strconcat basedig basenum
140 basenum=basedig
141 tmp=tmp/base
142 endwhile
143 return
144
145 :base2dec ;converts a number in any base to a decimal number
146 decnum=0
147 strlen basenum
148 len=result
149 for tmp 1 len
150 strcopy basenum tmp 1 basedig
151 strscan '0123456789ABCDEFabcdef' basedig
152 if result=0 break ;if not a num char, stop conversion
153 if result>16 result=result-6 ;take care of lower case
154 decnum=decnum*base
155 decnum=decnum+result-1
156 next
157 return
158 </pre>
159
160
161
162 </body>
163 </html>

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26