U:RDoc::AnyMethod[iI"unpack:ETI"String#unpack;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"IDecodes str (which may contain binary data) according to the ;TI"Dformat string, returning an array of each value extracted. The ;TI"Jformat string consists of a sequence of single-character directives, ;TI"7summarized in the table at the end of this entry. ;TI"$Each directive may be followed ;TI"Eby a number, indicating the number of times to repeat with this ;TI"Adirective. An asterisk (``*
'') will use up all ;TI"Hremaining elements. The directives sSiIlL
may each be ;TI"7followed by an underscore (``_
'') or ;TI"Aexclamation mark (``!
'') to use the underlying ;TI"Iplatform's native size for the specified type; otherwise, it uses a ;TI"Eplatform-independent consistent size. Spaces are ignored in the ;TI"Sformat string. See also String#unpack1
, Array#pack
.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [
I"="abc \0\0abc \0\0".unpack('A6Z6') #=> ["abc", "abc "]
;TI"B"abc \0\0".unpack('a3a3') #=> ["abc", " \000\000"]
;TI">"abc \0abc \0".unpack('Z*Z*') #=> ["abc ", "abc "]
;TI"F"aa".unpack('b8B8') #=> ["10000110", "01100001"]
;TI">"aaa".unpack('h2H2c') #=> ["16", "61", 97]
;TI"9"\xfe\xff\xfe\xff".unpack('sS') #=> [-2, 65534]
;TI"8"now=20is".unpack('M*') #=> ["now is"]
;TI"G"whole".unpack('xax2aX2aX1aX2a') #=> ["h", "e", "l", "l", "o"]
;T:@format0o;
; [I"DThis table summarizes the various formats and the Ruby classes ;TI"returned by each.;T@o;; [WI"Integer | |
;TI"'Directive | Returns | Meaning
;TI"H------------------------------------------------------------------
;TI">C | Integer | 8-bit unsigned (unsigned char)
;TI"IS | Integer | 16-bit unsigned, native endian (uint16_t)
;TI"IL | Integer | 32-bit unsigned, native endian (uint32_t)
;TI"IQ | Integer | 64-bit unsigned, native endian (uint64_t)
;TI"QJ | Integer | pointer width unsigned, native endian (uintptr_t)
;TI" | |
;TI":c | Integer | 8-bit signed (signed char)
;TI"Fs | Integer | 16-bit signed, native endian (int16_t)
;TI"Fl | Integer | 32-bit signed, native endian (int32_t)
;TI"Fq | Integer | 64-bit signed, native endian (int64_t)
;TI"Nj | Integer | pointer width signed, native endian (intptr_t)
;TI" | |
;TI"=S_ S! | Integer | unsigned short, native endian
;TI";I I_ I! | Integer | unsigned int, native endian
;TI" s> S!> s!> | Integer | same as the directives without ">" except
;TI"*L> l> L!> l!> | | big endian
;TI"I!> i!> | |
;TI"3Q> q> Q!> q!> | | "S>" is same as "n"
;TI"3J> j> J!> j!> | | "L>" is same as "N"
;TI" | |
;TI"IS< s< S!< s!< | Integer | same as the directives without "<" except
;TI"-L< l< L!< l!< | | little endian
;TI"I!< i!< | |
;TI"3Q< q< Q!< q!< | | "S<" is same as "v"
;TI"3J< j< J!< j!< | | "L<" is same as "V"
;TI" | |
;TI"Pn | Integer | 16-bit unsigned, network (big-endian) byte order
;TI"PN | Integer | 32-bit unsigned, network (big-endian) byte order
;TI"Ov | Integer | 16-bit unsigned, VAX (little-endian) byte order
;TI"OV | Integer | 32-bit unsigned, VAX (little-endian) byte order
;TI" | |
;TI"/U | Integer | UTF-8 character
;TI"Gw | Integer | BER-compressed integer (see Array.pack)
;TI"
;TI"Float | |
;TI"&Directive | Returns | Meaning
;TI"G-----------------------------------------------------------------
;TI">D d | Float | double-precision, native format
;TI">F f | Float | single-precision, native format
;TI"IE | Float | double-precision, little-endian byte order
;TI"Ie | Float | single-precision, little-endian byte order
;TI"PG | Float | double-precision, network (big-endian) byte order
;TI"Pg | Float | single-precision, network (big-endian) byte order
;TI"
;TI"String | |
;TI"&Directive | Returns | Meaning
;TI"G-----------------------------------------------------------------
;TI"_A | String | arbitrary binary string (remove trailing nulls and ASCII spaces)
;TI"6a | String | arbitrary binary string
;TI"5Z | String | null-terminated string
;TI"5B | String | bit string (MSB first)
;TI"5b | String | bit string (LSB first)
;TI"=H | String | hex string (high nibble first)
;TI", and i!> are available since Ruby 1.9.3.;T:
@fileI"pack.c;T:0@omit_headings_from_table_of_contents_below0I"'str.unpack(format) -> anArray
;T0[ I" (p1);T@ŒFI"String;TcRDoc::NormalClassI"
scanf;T0