C 中空格的转义序列是什么?

发布于 2024-09-11 05:27:35 字数 87 浏览 2 评论 0原文

我正在编写一个程序来计算空格、制表符和换行符。我记得制表符和换行符的转义序列是什么,但是空格呢? <代码>\b?或者那个是退格键?

I'm writing a program to count blanks, tabs, and newlines. I remember what the escape sequence for tabs and newlines are, but what about blanks? \b? Or is that backspace?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

洋洋洒洒 2024-09-18 05:27:35

你的意思是像“a b”中的“空白”?这是一个空格:' '

这是转义序列列表

You mean "blanks" like in "a b"? That's a space: ' '.

Here's a list of escape sequences for reference.

明月松间行 2024-09-18 05:27:35

如果要检查字符是否为空格,可以使用 中的 isspace() 函数。在默认的 C 语言环境中,它检查空格、制表符、换页符、换行符、回车符和垂直制表符。

If you want to check if a character is whitespace, you can use the isspace() function from <ctype.h>. In the default C locale, it checks for space, tab, form feed, newline, carriage return and vertical tab.

挽清梦 2024-09-18 05:27:35

空格就是 ' ',在十六进制中它存储为 20,相当于 32 的整数。例如:

if (a == ' ')

检查整数 32。同样:

if (a == '\n')

检查整数 10,因为 \n< /code> 是十六进制的 0A,即整数 10。
以下是其余最常见的转义序列及其十六进制和整数对应项:

code: │   name:                │Hex to integer:
──────│────────────────────────│──────────────
\n    │  # Newline             │  Hex 0A = 10
\t    │  # Horizontal Tab      │  Hex 09 = 9
\v    │  # Vertical Tab        │  Hex 0B = 11
\b    │  # Backspace           │  Hex 08 = 8
\r    │  # Carriage Return     │  Hex 0D = 13
\f    │  # Form feed           │  Hex 0C = 12
\a    │  # Audible Alert (bell)│  Hex 07 = 7
\\    │  # Backslash           │  Hex 5C = 92
\?    │  # Question mark       │  Hex 3F = 63
\'    │  # Single quote        │  Hex 27 = 39
\"    │  # Double quote        │  Hex 22 = 34
' '   │  # Space/Blank         │  Hex 20 = 32

Space is simply ' ', in hex it is stored as 20, which is the integer equivalent of 32. For example:

if (a == ' ')

Checks for integer 32. Likewise:

if (a == '\n')

Checks for integer 10 since \n is 0A in hex, which is the integer 10.
Here are the rest of the most common escape sequences and their hex and integer counterparts:

code: │   name:                │Hex to integer:
──────│────────────────────────│──────────────
\n    │  # Newline             │  Hex 0A = 10
\t    │  # Horizontal Tab      │  Hex 09 = 9
\v    │  # Vertical Tab        │  Hex 0B = 11
\b    │  # Backspace           │  Hex 08 = 8
\r    │  # Carriage Return     │  Hex 0D = 13
\f    │  # Form feed           │  Hex 0C = 12
\a    │  # Audible Alert (bell)│  Hex 07 = 7
\\    │  # Backslash           │  Hex 5C = 92
\?    │  # Question mark       │  Hex 3F = 63
\'    │  # Single quote        │  Hex 27 = 39
\"    │  # Double quote        │  Hex 22 = 34
' '   │  # Space/Blank         │  Hex 20 = 32
追星践月 2024-09-18 05:27:35

\b 是退格键 (ASCII 0x8)。您不需要对常规空格(ASCII 0x20)进行转义。您可以只使用' '

\b is backspace (ASCII 0x8). You don't need an escape for regular space (ASCII 0x20). You can just use ' '.

远山浅 2024-09-18 05:27:35

'\b' 是退格键,您实际上不需要空格的转义序列,因为 ' ' 就可以了。

'\b' is backspace, and you don't really need an escape sequence for blanks as ' ' will do just fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文