设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2645|回复: 2
打印 上一主题 下一主题

[讨论] 美兽看!(pack的资料,我先前说的似乎有错)

 关闭 [复制链接]

Lv1.梦旅人

逃兵

跳转到指定楼层
1
发表于 2006-11-20 20:57:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 后知后觉 于 2009-12-13 16:28 编辑

unpack  str.unpack( format ) -> anArray  

Decodes str (which may contain binary data) according to the format string, returning an array of each value extracted. The format string consists of a sequence of single-character directives, summarized in Table 22.8 on page 379. Each directive may be followed by a number, indicating the number of times to repeat with this directive. An asterisk (``*'') will use up all remaining elements. The directives sSiIlL may each be followed by an underscore (``_'') to use the underlying platform's native size for the specified type; otherwise, it uses a platform-independent consistent size. Spaces are ignored in the format string. See also Array#pack on page 286.
Directives for String#unpack Format  Function  Returns  
A String with trailing nulls and spaces removed. String
a String. String
B Extract bits from each character (msb first). String
b Extract bits from each character (lsb first). String
C Extract a character as an unsigned integer. Fixnum
c Extract a character as an integer. Fixnum
d Treat sizeof(double) characters as a native double. Float
E Treat sizeof(double) characters as a double in little-endian byte order. Float
e Treat sizeof(float) characters as a float in little-endian byte order. Float
f Treat sizeof(float) characters as a native float. Float
G Treat sizeof(double) characters as a double in network byte order. Float
g Treat sizeof(float) characters as a float in network byte order. Float
H Extract hex nibbles from each character (most significant first). String
h Extract hex nibbles from each character (least significant first). String
I Treat sizeof(int) 1 successive characters as an unsigned native integer. Integer
i Treat sizeof(int) 1 successive characters as a signed native integer. Integer
L Treat four1 successive characters as an unsigned native long integer. Integer
l Treat four1 successive characters as a signed native long integer. Integer
M Extract a quoted-printable string. String
m Extract a base64 encoded string. String
N Treat four characters as an unsigned long in network byte order. Fixnum
n Treat two characters as an unsigned short in network byte order. Fixnum
P Treat sizeof(char *) characters as a pointer, and return len characters from the referenced location. String
p Treat sizeof(char *) characters as a pointer to a null-terminated string. String
S Treat two1 successive characters as an unsigned short in native byte order. Fixnum
s Treat two1 successive characters as a signed short in native byte order. Fixnum
U Extract UTF-8 characters as unsigned integers. Integer
u Extract a UU-encoded string. String
V Treat four characters as an unsigned long in little-endian byte order. Fixnum
v Treat two characters as an unsigned short in little-endian byte order. Fixnum
X Skip backward one character. ---
x Skip forward one character. ---
Z String with trailing nulls removed. String
@ Skip to the offset given by the length argument. ---



1 May be modified by appending ``_'' to the directive.



"abc \0\0abc \0\0".unpack('A6Z6')  » ["abc", "abc "]  
"abc \0\0".unpack('a3a3')  » ["abc", " \000\000"]  
"aa".unpack('b8B8')  » ["10000110", "01100001"]  
"aaa".unpack('h2H2c')  » ["16", "61", 97]  
"\xfe\xff\xfe\xff".unpack('sS')  » [-2, 65534]  
"now=20is".unpack('M*')  » ["now is"]  
"whole".unpack('xax2aX2aX1aX2a')  » ["h", "e", "l", "l", "o"]  


本贴由论坛斑竹灼眼的夏娜结贴,如楼主认为问题未解决,请重新将此贴编辑为“有事请教”,并回帖叙述疑点即可~ ^-^
「If you judge people, you have no time to love them.」—— Mother Teresa

Lv1.梦旅人

逃兵

2
 楼主| 发表于 2006-11-20 20:57:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 后知后觉 于 2009-12-13 16:27 编辑

重复内容……
「If you judge people, you have no time to love them.」—— Mother Teresa

Lv1.梦旅人

月下可怜人

梦石
0
星屑
50
在线时间
10 小时
注册时间
2005-11-23
帖子
4085

第1届短篇游戏比赛亚军

3
发表于 2006-11-20 23:15:10 | 只看该作者
以下引用轮回者于2006-11-20 12:57:06的发言:

unpack  str.unpack( format ) -> anArray  


{/pz}...
http://rubycn.ce-lab.net/man/pack_template_string.html

只是好奇而已,不会真的用到的...谢谢了.
纵然千里外,我等雁归来。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-12-18 10:09

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表