Characters and strings

Every letter, digit, and punctuation mark is a character. There are also many characters that are invisible on screen, such as the space, tab, and carriage-return characters.

Most programming languages provide a data type called 'character' or 'char'.

Character sets

Each value represents a single character from a predefined set, such as ASCII or Unicode. Each character has its own binary pattern.

Strings

Most programming languages have a data type called a string, which is used for data values that are made up of ordered sequences of characters, such as "hello world". A string can contain any sequence of characters, visible or invisible, and characters may be repeated. The number of characters in the string is called its length, and "hello world" has length 11 - made up of 10 letters and 1 space. There is usually a restriction on the maximum length of a string. There is also such a thing as an empty string, which contains no characters - length 0.

A string can be a constant or variable. If it is a constant, it is usually written as a sequence of characters enclosed in single or double quotation marks, ie 'hello' or "hello".

curriculum-key-fact
Note that a string such as "573" is not the same as the number 573, because a string is a sequence of characters whereas a number is a sequence of digits.

All keyboard input and text output is in the form of character strings.