Core Function BinaryToStr
From Sputnik Wiki
(Difference between revisions)
(→Example) |
|||
Line 36: | Line 36: | ||
=== Example === | === Example === | ||
+ | |||
+ | ASCII Example | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | $binary = Pack(" | + | $binary = Pack("A*", "Hello World!"); |
− | + | ||
− | + | ||
− | + | ||
$binStr = BinaryToStr($binary); | $binStr = BinaryToStr($binary); | ||
echo "String Content: $binStr\n"; | echo "String Content: $binStr\n"; | ||
− | + | // Prints: | |
− | + | // String Content: Hello World! | |
− | + | ||
− | / | + | |
− | Prints: | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | String Content: Hello World! | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Revision as of 15:31, 26 September 2013
BinaryToStr( <binary-array>, <flag> )
Contents |
Description
Returns a new string containing the binary data as raw bytes.
Parameters
binary-array
The binary variable to use.
flag
Optional; Encoding to use.
Choices are:
"ASCII" = Each byte will directly be converted to a single character and returned as a string
"UTF8" = Similar to ASCII but uses 2 bytes of one for each character of the string it will make
"UNICODE" = Alias to UTF8 (or whatever Sputnik is using for Unicode strings)
Default: "ASCII"
Return Value
Returns a new string containing the binary data as raw bytes.
Remarks
Sputnik strings allow null terminators inside them so they can be used just like raw binary data this is useful since you can treat it as a string and use all the string functions but yet it's also binary.
Example
ASCII Example
$binary = Pack("A*", "Hello World!"); $binStr = BinaryToStr($binary); echo "String Content: $binStr\n"; // Prints: // String Content: Hello World!