Core Function BinaryFromStr

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(flag)
(Example)
Line 50: Line 50:
 
// 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>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 15:40, 26 September 2013

BinaryFromStr( <string>, <flag> )

Contents

Description

Returns a new binary variable created from a strings raw bytes

Parameters

string

The string to use.

flag

Optional; Encoding to use.

Choices are:

"ASCII"

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

"UTF8"

"UTF7"

"UTF32"

Default: "ASCII"

Return Value

Returns a new binary variable created from a strings raw bytes

Remarks

None.

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: ふふふ
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox