使用字符的输入和输出

2024 年 8 月 29 日 | 阅读 3 分钟

输入项和输出项很简单。 有时使用句点和引号很复杂,并且并非总是合适。 例如,定义一个从键盘读取一系列字符并计算元音数量的谓词确实很乏味。 对于这种问题,更好的方法是一次输入一个字符。 要应用此方法,我们必须知道字符的 ASCII 值。 ASCII(美国信息交换标准代码)值是一个介于 0 到 255 之间的整数。

所有非打印字符和打印字符都有其对应的 ASCII 值。 小于或等于 32 的字符的 ASCII 值称为控制字符或空格字符。

下表显示了可打印字符和其他一些字符的 ASCII 值。

数字Character描述
9Tab (制表符)
10end of record (记录结束)
32空格
33!exclamation mark (感叹号)
34“ (双引号)quotation mark (引号)
35#number sign (井号)
36$dollar sign (美元符号)
37%percent sign (百分号)
38&ampersand (与号)
39‘ (单引号)apostrophe (撇号)
40(left parenthesis (左括号)
41)right parenthesis (右括号)
42*asterisk (星号)
43+plus sign (加号)
44,comma (逗号)
45-hyphen (连字符)
46.period (句点)
47/slash (斜杠)
4800 digit (数字0)
4911 digit (数字1)
5022 digit (数字2)
5133 digit (数字3)
5244 digit (数字4)
5355 digit (数字5)
5466 digit (数字6)
5577 digit (数字7)
5688 digit (数字8)
5799 digit (数字9)
58:colon (冒号)
59;semicolon (分号)
60<less-than (小于号)
61=equals-to (等于号)
62>greater-than (大于号)
63?question mark (问号)
64@at sign (@)
65Auppercase A (大写A)
66Buppercase B (大写B)
67Cuppercase C (大写C)
68Duppercase D (大写D)
69Euppercase E (大写E)
70Fuppercase F (大写F)
71Guppercase G (大写G)
72Huppercase H (大写H)
73Iuppercase I (大写I)
74Juppercase J (大写J)
75Kuppercase K (大写K)
76Luppercase L (大写L)
77Muppercase M (大写M)
78Nuppercase N (大写N)
79Ouppercase O (大写O)
80Puppercase P (大写P)
91Quppercase Q (大写Q)
82Ruppercase R (大写R)
83Suppercase S (大写S)
84Tuppercase T (大写T)
85Uuppercase U (大写U)
86Vuppercase V (大写V)
87Wuppercase W (大写W)
88Xuppercase X (大写X)
89Yuppercase Y (大写Y)
90Zuppercase Z (大写Z)
91[left square bracket (左方括号)
92\backslash (反斜杠)
93]right square bracket (右方括号)
94^Caret (脱字号)
95_underscore (下划线)
96`grave accent (重音符)
97Alowercase a (小写a)
98Blowercase b (小写b)
99Clowercase c (小写c)
100Dlowercase d (小写d)
101Elowercase e (小写e)
102Flowercase f (小写f)
103Glowercase g (小写g)
104Hlowercase h (小写h)
105Ilowercase i (小写i)
106Jlowercase j (小写j)
107Klowercase k (小写k)
108Llowercase l (小写l)
109Mlowercase m (小写m)
110Nlowercase n (小写n)
111Olowercase o (小写o)
112Plowercase p (小写p)
113Qlowercase q (小写q)
114Rlowercase r (小写r)
115Slowercase s (小写s)
116Tlowercase t (小写t)
117Ulowercase u (小写u)
118Vlowercase v (小写v)
119Wlowercase w (小写w)
120Xlowercase x (小写x)
121Ylowercase y (小写y)
122Zlowercase z (小写z)
123{left curly brace (左大括号)
124|vertical bar (竖线)
125}right curly brace (右大括号)
126~tilde (波浪号)