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.