ANSI 转义字符

时间:2024-03-15 22:22:28

ANSI C语言中的全部转义字符序列如下:##

a:响铃符

b:回退符

f:换页符

n:换行符

r:回车符

t:横向制表符

v:纵向制表符

:反斜杠

?:问号

':单引号

":双引号

ooo:八进制数

xhh:十六进制数

在编程中经常看到如:\033的转义字符,’\033’ == ‘\x1b’

‘\0’:8进制, ‘\x’:16进制
它们的具体意思如下:

转义字符 说明
\033[0m 关闭所有属性
\033[1m 设置高亮度
\033[4m 下划线
\033[5m 闪烁
\033[7m 反显
\033[8m 消隐
\033[30m-\33[37m 设置前景颜色
\033[40m-\33[47m 设置背景颜色
\033[nA 光标上移n行
\033[nB 光标下移n行
\033[nC 光标右移n行
\033[nD 光标左移n行
\033[y;xH 设置光标位置
\033[2J 清屏
\033[K 清除从光标到行尾的内容
\034[s 保存光标位置
\033[u 恢复光标位置
\033[?25l 隐藏光标
\033[?25h 显示光标

ASCII Table and Description

ASCII stands for American Standard Code for Information Interchange. Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as ‘a’ or ‘@’ or an action of some sort. ASCII was developed a long time ago and now the non-printing characters are rarely used for their original purpose. Below is the ASCII character table and this includes descriptions of the first 32 non-printing characters. ASCII was actually designed for use with teletypes and so the descriptions are somewhat obscure. If someone says they want your CV however in ASCII format, all this means is they want ‘plain’ text with no formatting such as tabs, bold or underscoring - the raw format that any computer can understand. This is usually so they can easily import the file into their own applications without issues. Notepad.exe creates ASCII text, or in MS Word you can save a file as ‘text only’
ANSI 转义字符

Extended ASCII Codes

ANSI 转义字符