什么是Pascal风格的字符串? [英] What is a Pascal-style string?

查看:238
本文介绍了什么是Pascal风格的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Photoshop文件格式文档提到了 Pascal字符串而不解释它们是什么。

The Photoshop file format documentation mentions Pascal strings without explaining what they are.

那么,它们是什么,以及它们如何编码?

So, what are they, and how are they encoded?

推荐答案

Pascal样式的字符串有一个前导字节( length ),后跟 length 字节数据。

A Pascal-style string has one leading byte (length), followed by length bytes of character data.

这意味着Pascal样式的字符串只能编码长度在0到255个字符之间的字符串(假设单字节字符编码例如

This means that Pascal-style strings can only encode strings of between 0 and 255 characters in length (assuming single-byte character encodings such as ASCII).

顺便说一句,另一种流行的字符串编码是 C风格的字符串,它们没有长度说明符,但使用零字节表示字符串的结尾。因此,它们没有长度限制。

As an aside, another popular string encoding is C-style strings which have no length specifier, but use a zero-byte to denote the end of the string. They therefore have no length limit.

其他编码可能会使用更多的前缀字节以方便较长的字符串。终止符字节/前哨也可以与长度前缀一起使用。

Yet other encodings may use a greater number of prefix bytes to facilitate longer strings. Terminator bytes/sentinels may also be used along with length prefixes.

这篇关于什么是Pascal风格的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆