mem_get¶
mem_get reads bytes from a string and converts the data.
- rvValues = mem_get(ssString, pos, ssType, count)
- rvValues = mem_get(ssString, pos, ssType, count, nRecLen)
- rvValues = mem_get(ssString, pos, ssType, count, rvOptions)
- ssSubString = mem_get(ssString, pos, count)
Return Value
rvValues is a vector of length count.
Parameters
- ssString
ssString is a scalar string.
- pos
pos is a number between 1 and
mem_len(ssString)
. The number sets the first character to start reading.
- ssType
Is the data type of the data:
Type
Description
“int8” or “char”
One signed byte (-127 bis 127).
“uint8” or “uchar”
One unsigned byte (0 bis 255).
“wchar_t”
UTF-16 Unicode character (2 bytes).
“int16”
16-bit integer (2 bytes).
“uint16”
16-bit unsigned integer (2 bytes).
“int32”
32-bit integer (4 bytes).
“uint32”
32-bit unsigned integer (4 bytes).
“int64”
64-bit integer (8 bytes). Because UniScript stores 64-bit integers in double format, only (approx.) 52 bits are valid.
“uint64”
64-bit unsigned integer (8 bytes). Because UniScript stores 64-bit integers in double format, only (approx.) 52 bits are valid.
“float”
32-bit real values (4 bytes).
“double”
64-bit real values (8 bytes).
- count
count is the number of values to read.
- nRecLen
nRecLen is the number of bytes to skip before reading the next value (distance between two values).
- rvOptions
rvOptions is a vector [nRecLen, nBits, nBitOffset, bBigEndian].
nRecLen is the number of bytes to skip before reading the next value (distance between two values). Default is 0, if rvOptions is not specified.
nBits: 0: The data type specified in ssType is used. For example 32 bits for “int32”. 1 .. 64: Number of bits to read. The value must be smaller or equal to the size of the data type specified in ssType. Example: * For ssType = “int16” nBits can be a number between 9 and 16 * For ssType = “int32” nBits can be a number between 17 and 32.
nBitOffset: 0 .. 7. Default is 0, if rvOptions is not specified.
bBigEndian: 1: Big Endian byte order (Motorola), 0: Little Endian byte order (Intel). Default is 0, if rvOptions is not specified.
Example
// Read 100 floats from Buffer:
// Read Buffer from file, read the first value starting at positon 20 byte.
// The distance to the next value is 72 bytes.
// Read all 100 values.
data_buffer = fread(fp, "char8", lenbuffer);
rvY = mem_get(data_buffer, 20, "float", 100, 72);
See also mem_set.
History
Version |
Description |
---|---|
R2012.4 |
New parameter rvOptions an call with 3 parameters to extract a part of a substring. New types in ssType (“int8” and “uint8”). |
5.8.2 |
New parameter nRecLen. |
5.0.0 |
New type “wchar_t”. |
4.2.0 |
New. |
See also
Overview Strings, mem_alloc, mem_set, mem_len, strchar, strextract
id-1871369