Core Function BinaryToStr

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
m (1 revision)
 
(7 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
BinaryToStr( <binary-array>, <flag> )
+
BinaryToStr( <binary-array>, <flag>, <start>, <length> )
 
</pre>
 
</pre>
  
Line 19: Line 19:
 
Choices are:
 
Choices are:
  
"ASCII" = Each byte will directly be converted to a single character and returned as a string
+
"RAW" = Forces each byte in the binary to directly become a character in the 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)
 
"UNICODE" = Alias to UTF8 (or whatever Sputnik is using for Unicode strings)
  
Default: "ASCII"
+
"ASCII"
 +
 
 +
"UTF8"
 +
 
 +
"UTF7"
 +
 
 +
"UTF32"
 +
 
 +
Default: "RAW"
  
 
=== Return Value ===
 
=== Return Value ===
Line 45: Line 51:
 
// Prints:
 
// Prints:
 
// String Content: Hello World!
 
// String Content: Hello World!
 +
</syntaxhighlight>
 +
 +
UNICODE (UTF8) Example
 +
 +
<syntaxhighlight lang="sputnik">
 +
$binary = BinaryFromStr("ふふふ", "UTF8");
 +
printr $binary;
 +
$binStr = BinaryToStr($binary, "UTF8");
 +
echo "String Content: $binStr\n";
 +
// Prints:
 +
// String Content: ふふふ
 +
</syntaxhighlight>
 +
 +
Using start parameter to get everything starting with World
 +
 +
<syntaxhighlight lang="sputnik">
 +
$binary = BinaryFromStr("Hello World!", "ASCII");
 +
$binStr = BinaryToStr($binary, "ASCII", 6);
 +
echo "String Content: $binStr\n";
 +
// Prints:
 +
// String Content: World!
 +
</syntaxhighlight>
 +
 +
Using start and length parameter to get just World
 +
 +
<syntaxhighlight lang="sputnik">
 +
$binary = BinaryFromStr("Hello World!", "ASCII");
 +
$binStr = BinaryToStr($binary, "ASCII", 6, 5);
 +
echo "String Content: $binStr\n";
 +
// Prints:
 +
// String Content: World
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:37, 14 June 2015

BinaryToStr( <binary-array>, <flag>, <start>, <length> )

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:

"RAW" = Forces each byte in the binary to directly become a character in the string

"UNICODE" = Alias to UTF8 (or whatever Sputnik is using for Unicode strings)

"ASCII"

"UTF8"

"UTF7"

"UTF32"

Default: "RAW"

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!

UNICODE (UTF8) Example

$binary = BinaryFromStr("ふふふ", "UTF8");
printr $binary;
$binStr = BinaryToStr($binary, "UTF8");
echo "String Content: $binStr\n";
// Prints:
// String Content: ふふふ

Using start parameter to get everything starting with World

$binary = BinaryFromStr("Hello World!", "ASCII");
$binStr = BinaryToStr($binary, "ASCII", 6);
echo "String Content: $binStr\n";
// Prints:
// String Content: World!

Using start and length parameter to get just World

$binary = BinaryFromStr("Hello World!", "ASCII");
$binStr = BinaryToStr($binary, "ASCII", 6, 5);
echo "String Content: $binStr\n";
// Prints:
// String Content: World
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox