Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6410 - (show annotations) (download) (as text)
Thu Jun 23 02:17:49 2016 UTC (7 years, 11 months ago) by doda
File MIME type: text/html
File size: 2546 byte(s)
r6409のコミット漏れ
・改行の調整
・行末の空白の削除Merge branch 'doc-htmlfix'
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 &gt; 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&gt;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 &amp; 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&amp;isn
94 strscan sn '.'
95 strcopy sn result+1 999 sn
96 strscan ip '.'
97 strcopy ip result+1 999 ip
98 if result&gt;0 strconcat net '.'
99 loop while result&gt;0
100 messagebox bits 'bits'
101 messagebox net 'net'
102 </pre>
103
104
105 </body>
106 </html>

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