Control character
In computing and telecommunications, a control character is a code point in a character set (such as ASCII or Unicode) that does not represent a printable symbol but instead initiates, modifies, or terminates a control function, typically affecting the behavior of a device, a data stream, or a communication protocol.
History
Control characters originated in the early days of telegraphy and were later formalized in the ASCII standard (American Standard Code for Information Interchange) in the 1960s. The original telegraph systems used characters such as "line feed" and "carriage return" to control the movement of paper in teleprinters. ASCII reserved the first 32 code points (0–31, decimal) and the DEL code (127) for control functions, while later standards such as ISO/IEC 646 and Unicode extended this concept to include additional control sets like the C1 set (128–159 in ISO 8859 and Unicode).
C0 Control Characters (ASCII)
The ASCII control characters (code points 0–31) are collectively known as the C0 set. They are grouped by function:
- Transmission control (e.g., STX, ETX, ACK, NAK): Used to manage data flow, framing, and error detection in serial communication protocols.
- Format effectors (e.g., BS, HT, LF, FF, CR): Control the layout of text on output devices, such as moving the cursor, advancing paper, or inserting tabs.
- Information separators (e.g., FS, GS, RS, US): Used to delimit logical records or fields in data streams.
- Device control (e.g., DC1–DC4): Historically employed to turn attached peripherals on and off (e.g., DC1 for "XON", DC3 for "XOFF").
- Others: NUL (null character) for padding, BEL (bell) to produce an audible alert, and ESC to introduce escape sequences.
The DEL character (code 127) is considered a control character as well, originally used to delete a previously punched hole in paper tape.
C1 Control Characters
In extensions such as ISO/IEC 6429 (ECMA-48), the C1 control set occupies code points 128–159 (0x80–0x9F) in 8-bit character encodings. Unicode also reserves this range for control characters. Notable C1 codes include:
- IND (Index), NEL (Next Line): Analogues to line feed and newline.
- HTS (Horizontal Tab Set), VTS (Vertical Tab Set): Set tab stops.
- CSI (Control Sequence Introducer): Initiates ANSI escape sequences used in terminal control (e.g., cursor movement, color changes).
- SPA (Start of Protected Area), EPA (End of Protected Area): Used in word-processing and terminal emulation.
In Unicode, C1 characters are explicitly defined but are rarely used directly in modern text; they are often replaced by equivalent escape sequences or markup.
Control Characters in Unicode
Unicode preserves the C0 and C1 control characters for backward compatibility, but it also includes additional dedicated control-like characters such as:
- U+200B ZERO WIDTH SPACE: A formatting control that allows line breaks without visible spacing.
- U+200C ZERO WIDTH NON-JOINER: Prevents cursive joining in scripts like Arabic.
- U+FEFF BYTE ORDER MARK (BOM): Used at the start of a text stream to indicate byte order or encoding; also acts as a zero-width non-breaking space.
Unicode also defines ISO 14651/UCA controls for collation and directional formatting characters (e.g., U+202A LEFT-TO-RIGHT EMBEDDING) for bidirectional text. These are sometimes classified as "format characters" rather than traditional control characters.
Usage
Control characters are essential in many contexts:
- Terminal emulation: Escape sequences (starting with ESC) control cursor position, screen clearing, text attributes, and color.
- Serial communication: Protocols like XON/XOFF use DC1 and DC3 for flow control; ASCII ACK/NAK are used in error detection.
- Data delimiters: In formats such as CSV or log files, Information Separators (RS, GS, US) occasionally serve as field or record separators.
- Text processing: The line feed (LF, U+000A) and carriage return (CR, U+000D) define newlines in different operating systems (Unix vs. Windows vs. classic Mac OS).
- Punched tape and legacy media: NUL and DEL were used for padding and deletion in physical tape.
Examples of Common Control Characters
| Code (dec) | Name | Abbreviation | Typical Use |
|------------|---------------------------|--------------|--------------------------------------|
| 0 | Null | NUL | Padding, string terminator in C |
| 7 | Bell | BEL | Audible alert on terminals |
| 8 | Backspace | BS | Move cursor left one position |
| 9 | Horizontal Tab | HT | Advance to next tab stop |
| 10 | Line Feed | LF | Move cursor down one line (Unix newline) |
| 12 | Form Feed | FF | Eject page or clear screen |
| 13 | Carriage Return | CR | Return cursor to beginning of line |
| 26 | Substitute | SUB | End-of-file marker in some systems |
| 27 | Escape | ESC | Start escape sequence |
| 127 | Delete | DEL | Delete previous character; nothing in ASCII terminal |
Modern Context and Challenges
As computing evolved, many historical control functions became obsolete or absorbed into higher-level protocols. In modern software:
- Control characters are often displayed as visual placeholders (e.g.,
^Cfor ETX) or handled invisibly by user interfaces. - The distinction between "control" and "formatting" characters has blurred. For example, Unicode format characters like the soft hyphen (U+00AD) enable invisible line-breaking hints, while zero-width spaces influence word-breaking without any visible glyph.
- Security concerns arise when control characters are embedded in user-generated text (e.g., injected escape sequences in terminal emulators leading to "terminal injection" attacks).
- Some legacy control characters (e.g., the C1 set) are deprecated in favor of Unicode markup like directional overrides and explicit formatting tags.
Despite their declining visibility, control characters remain a fundamental part of character encoding standards and continue to be used in system-level programming, text protocols, and internationalized text processing.
你感兴趣的百科
国际象棋
国际象棋(Chess)是一种在8×8方格、共64格的棋盘上由两名棋手对弈的策略性棋类游戏,双方各统领十六枚棋子,以将死对方的王为最终目标。国际象棋被广泛视为世界上历史最悠久、智力要求最高的棋艺活动之一,兼具艺术、科学与竞技体育的特质,在全球...
尼古拉·特斯拉(Nikola Tesla)
尼古拉·特斯拉(1856年7月10日—1943年1月7日)是塞尔维亚裔美籍发明家、电气工程师、机械工程师和未来学家,以设计现代交流电(AC)供电系统而闻名于世,被誉为“交流电之父”和“无线电之父”之一。他一生拥有约三百项专利(其中美国专利一...
Anthropic
Anthropic(中文名称常译作“安斯罗皮克”或音译“人类技术公司”,一般直接使用英文名称)是一家总部位于美国加利福尼亚州旧金山的人工智能安全与研究公司。该公司由前OpenAI研究人员于2021年创立,联合创始人包括达里奥·阿莫迪与达妮埃...
月球
月球是地球唯一的天然卫星,也是太阳系中体积第五大的卫星,与地球的平均距离约为384,400千米(238,900英里)。它是地球夜空中最明亮、最大的天体,对地球的潮汐系统、地轴倾角的稳定起着根本性作用,并深刻影响了人类文明的文化、神话与科学发...
评论区 (0)
还没有评论,来抢沙发!