1. Characters:
Characters include letters, numbers, arithmetic symbols, punctuation marks and others symbols, as well as some functional symbols. When characters are stored in the computer, the corresponding binary code representing the character should be specified. The selection of codes should be consistent with the specifications of the relevant peripheral devices. These peripheral devices include keyboard console input and output, printer output, and so on. When
characters are input, they are automatically converted into binary codes and stored in the machine; when output, the binary codes in the computer are automatically converted into characters. The conversion of both is achieved by peripheral devices. The
character is the smallest data access unit in the data structure. A character is usually represented by 8 binary bits (one byte), but there are also a few computer systems that use 6 binary character representations. The size of the character set in a system is completely determined by the system itself. The number of characters available for computers is generally 128 to 256 (excluding Chinese characters). After each character enters the computer, it will be converted into an 8-bit binary number. Different computer systems and different languages have different character ranges.
In ASCII encoding, one English alphabetic character requires 1 byte to store.
In GB 2312 encoding or GBK encoding, one Chinese character storage requires 2 bytes. In UTF-8 encoding, the storage of an English alphabetic character requires 1 byte, and the storage of a Chinese character requires 3 to 4 bytes. In UTF-16 encoding, the storage of an English alphabetic character or a Chinese character requires 2 bytes (some Chinese characters in the Unicode extension area require 4 bytes to store). In UTF-32 encoding, the storage of any character in the world requires 4 bytes.
2. String:
A string or string (String) is a string of characters composed of numbers, letters, and underscores. Generally recorded as s=“a1a2···an” (n>=0). It is a data type that represents text in programming languages. In programming, a string is a continuous sequence of symbols or values, such as a symbol string (a string of characters) or a binary digit string (a string of binary digits).
Usually the entire string is used as the operation object, such as: finding a substring in the string, obtaining a substring, inserting a substring at a certain position in the string, deleting a substring, etc. The necessary and sufficient conditions for two strings to be equal are: the lengths are equal, and the characters at each corresponding position are equal. Assume that p and q are two strings. The operation of finding the position where q first appears in p is called pattern matching. The two most basic storage methods of strings are sequential storage and linked storage.
The above is the detailed content of What do characters and strings mean?. For more information, please follow other related articles on the PHP Chinese website!