1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
<html>
<head>
<title>EAGLE Help: string</title>
</head>
<body bgcolor=white>
<font face=Helvetica,Arial>
<hr>
<i>EAGLE Help</i>
<h1><center>string</center></h1>
<hr>
The data type <tt>string</tt> is used to store textual information,
like the name of a part or net.
<p>
A variable of type <tt>string</tt> is not limited in it's size (provided
there is enough memory available).
<p>
Variables of type <tt>string</tt> are defined without an explicit
<i>size</i>. They grow automatically as necessary during program
execution.
<p>
The elements of a <tt>string</tt> variable are of type
<tt><a href=155.htm>char</a></tt> and
can be accessed individually by using <tt>[index]</tt>.
The first character of a <tt>string</tt> has the index <tt>0</tt>:
<pre>
string s = "Layout";
printf("Third char is: %c\n", s[2]);
</pre>
This would print the character <tt>'y'</tt>. Note that <tt>s[2]</tt> returns
the <b>third</b> character of <tt>s</tt>!
<p>
<b>See also</b> <a href=201.htm>Operators</a>,
<a href=230.htm>Builtin Functions</a>,
<a href=144.htm>String Constants</a>
<p>
<b>Implementation details</b>
<p>
The data type <tt>string</tt> is actually implemented through native C-type
zero terminated strings (i.e. <tt>char[]</tt>). Looking at the following
variable definition
<pre>
string s = "abcde";
</pre>
<tt>s[4]</tt> is the character <tt>'e'</tt>, and <tt>s[5]</tt> is the character
<tt>'\0'</tt>, or the integer value <tt>0x00</tt>.
This fact may be used to determine the end of a string without using the
<tt><a href=260.htm>strlen()</a></tt> function, as in
<pre>
for (int i = 0; s[i]; ++i) {
// do something with s[i]
}
</pre>
It is also perfectly ok to "cut off" part of a string by "punching" a zero
character into it:
<pre>
string s = "abcde";
s[3] = 0;
</pre>
This will result in <tt>s</tt> having the value <tt>"abc"</tt>.
<hr>
<table width=100% cellspacing=0 border=0><tr><td align=left><font face=Helvetica,Arial>
<a href=index.htm>Index</a>
</font></td><td align=right><font face=Helvetica,Arial size=-1>
<i>Copyright © 2005 CadSoft Computer GmbH</i>
</font></td></tr></table>
<hr>
</font>
</body>
</html>
|