Strings
A
string
is a collection of characters.
abcdefg, Hello
World, and Boeing
747 are all examples of strings. Consider the
following NASL script:
mystring="Hello. I am a string!\n"; display(mystring);
The \n at the end of
mystring is an escape character and is equivalent
to a newline character. Table 1-1 lists common
escape characters applicable to NASL.
Table 1-1. Escape characters
|
Escape character |
Description |
|---|---|
\' |
Single quote. |
\" |
Double quote. |
\\ |
Backslash. |
\r |
Line feed. |
\n |
Newline. |
\t |
Horizontal tab. |
\x(integer) |
ASCII equivalent. For example, |
\v |
Vertical tab. |
Note that a string inside double quotes (“)
is left as is. Therefore, if you define a string using double quotes,
escape sequences will not be translated. Also note that the
display( )
function calls the string( )
function before displaying data on the
console, and it is the string( ) function that
converts the escape sequences. That is why our escape sequences are
translated in the preceding examples even though we define them using
double quotes.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access