String

A string constant is a character sequence enclosed in double quotes:

"this is a string"

The backslash convention for representing special characters can also be used within a string. This makes it possible to represent the double quote and the escape character backslash \ within a string. It is not possible for a string to contain the \0 (NUL) character since it is used to represent the end of string internally. Therefore,

"this is the end\0here we passed the end of string"

is equivalent to

"this is the end"

If s denotes a string expression, and i an index (an integer expression) then s[i] denotes the ith character in the string.

An individual character of a string can be accessed randomly by giving the index - an integer expression enclosed in [] - after the string expression. The first character is numbered 1 (not zero). For example, if

s = "abcdef";

then

s[1]is the first character of s, i.e. 'a'.
s[i]is the ith character of s.

It is illegal to index beyond the current number of characters in a string. So s[7] is an error since s has only six characters. The suffix operator # returns the current number of characters in the string. In the last example, s# is 6. For the empty string, ""# is 0.


[BACK] [FORWARD] [HOME] [UP] [HELP]