Cloudbook: C

  1. Home
  2. Variables
  3. Strings
  4. § 1 exercise →
Strings

A string is text - a sequence of characters. It could be as short as a single character or as long as the entire contents of a book. In fact, it can be shorter than a single character, there is the empty string which contains zero characters.

A string literal introduces a string value into a Perl program. The string value can be used immediately, as in:

        print "Hello World!" ;
        
or it can be stored in a variable for later use:
        $s = "Hello World!" ;
        
Although it is possible to put the entire contents of a book in a string, you can't directly have such embellishments as boldface or strike-through in a string. A string is a sequence of characters and only what is a character can go into a string.

The simplest set of characters are plain text characters. These include the letters both little, a through z, and big, A through Z; the digits, 0 through 9; punctuation of all sorts and very importantly, the space character. For the purposes of plain text, space is a character.

The above mentioned characters are all printable characters. In the set of plain text characters, there are several non-printing characters, which are also called control characters. Since they are non-printing, they aren't represented directly but by character sequences that are interpreted non-literally.

The only non-printing character that concerns us at the moment is the newline character. When a newline character printed, it causes and end of line, and printing begins at the beginning of the next line. The newline character is reprsented as the two character sequence \n.

We differ to the next section the question of what to do when you want to print \n, as in "\" followed by "n".