The data type string is used to store textual information, like the name of a part or net.

A variable of type string is not limited in it's size (provided there is enough memory available).

Variables of type string are defined without an explicit size. They grow automatically as necessary during program execution.

The elements of a string variable are of type char and can be accessed individually by using [index]. The first character of a string has the index 0:

string s = "Layout";
printf("Third char is: %c\n", s[2]);
This would print the character 'y'. Note that s[2] returns the third character of s!

See also Operators, Builtin Functions, String Constants

Implementation details

The data type string is actually implemented through native C-type zero terminated strings (i.e. char[]). Looking at the following variable definition

string s = "abcde";
s[4] is the character 'e', and s[5] is the character '\0', or the integer value 0x00. This fact may be used to determine the end of a string without using the strlen() function, as in
for (int i = 0; s[i]; ++i) {
    // do something with s[i]
It is also perfectly ok to "cut off" part of a string by "punching" a zero character into it:
string s = "abcde";
s[3] = 0;
This will result in s having the value "abc".
Index Copyright © 2005 CadSoft Computer GmbH