编码和转义一样吗?

发布于 2024-10-06 00:21:58 字数 221 浏览 4 评论 0原文

我对编码是否与转义相同的理论感兴趣?根据维基百科

转义字符是一个字符 这调用了一个替代方案 后续解释 字符序列中的字符。

我目前的想法是它们是不同的。转义是指您将转义字符放在元字符前面以将其标记为与正常情况下的行为不同。

另一方面,编码就是将数据转换为另一种形式,并且在想要读取原始内容时将其解码回其原始形式。

I am interested in theory on whether Encoding is the same as Escaping? According to Wikipedia

an escape character is a character
which invokes an alternative
interpretation on subsequent
characters in a character sequence.

My current thought is that they are different. Escaping is when you place an escape charater in front of a metacharacter(s) to mark it/them as to behave differently than what they would have normally.

Encoding, on the other hand, is all about transforming data into another form, and upon wanting to read the original content it is decoded back to its original form.

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

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

发布评论

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

评论(3

缺⑴份安定 2024-10-13 00:21:58

转义是编码的子集:仅通过在特殊字符前添加前缀来对某些字符进行编码,而不是将(通常是所有或许多)字符转移到另一种表示形式。

转义示例:

  • 在 SQL 语句中: ... WHERE name='O\' Reilly'
  • 在 shell 中: ls Thirty\ Seconds\ *
  • 许多编程语言: "\"Test\" 字符串(或 """Test"""

编码示例:

  • 输出 user 时将 < 替换为 < HTML 中的输入
  • 字符编码,如 UTF-8
  • 使用不包含所需字符的序列,如 \u0061 表示 a

Escaping is a subset of encoding: You only encode certain characters by prefixing a special character instead of transferring (typically all or many) characters to another representation.

Escaping examples:

  • In an SQL statement: ... WHERE name='O\' Reilly'
  • In the shell: ls Thirty\ Seconds\ *
  • Many programming languages: "\"Test\" string (or """Test""")

Encoding examples:

  • Replacing < with < when outputting user input in HTML
  • The character encoding, like UTF-8
  • Using sequences that do not include the desired character, like \u0061 for a
流星番茄 2024-10-13 00:21:58

它们是不同的,我认为您正确地理解了它们的区别。

编码是指将文本的逻辑表示形式(“逻辑字符串”,例如 Unicode)转换为明确定义的二进制数字序列(“物理字符串”,例如 ASCII、UTF-8、UTF-16)。转义符是一个特殊字符(通常是反斜杠:“\”),它会对转义符后面的字符进行不同的解释;当您需要将大量符号编码为少量不同(且有限)的位序列时,转义是必要的。

They're different, and I think you're getting the distinction correctly.

Encoding is when you transform between a logical representation of a text ("logical string", e.g. Unicode) into a well-defined sequence of binary digits ("physical string", e.g. ASCII, UTF-8, UTF-16). Escaping is a special character (typically the backslash: '\') which initiates a different interpretation of the character(s) following the escape character; escaping is necessary when you need to encode a larger number of symbols to a smaller number of distinct (and finite) bit sequences.

笑咖 2024-10-13 00:21:58

他们确实不同。

你几乎答对了。

They are indeed different.

You pretty much got it right.

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