Skip to content

ProtoString encodeAs() Method

Seth Clydesdale edited this page May 23, 2015 · 5 revisions

<< Back to Conversion Methods

Example

Encoding a text string as four different types with ProtoString.

/*** DECIMAL CONVERSION ***/
'Hello'.encodeAs('decimal'); // returns '72 101 108 108 111'

/*** HEXADECIMAL CONVERSION ***/
'Hello'.encodeAs('hex'); // returns '48 65 6c 6c 6f'

/*** BINARY CONVERSION ***/
'Hello'.encodeAs('binary'); // returns '1001000 1100101 1101100 1101100 1101111'

/*** HTML ENTITY CONVERSION ***/
'&$♥♦♣'.encodeAs('entity'); // returns '&#38;&#36;&#9829;&#9830;&#9827;'

Description

The encodeAs() method is used to encode all the characters in a string as one of the following types.

  • Decimal
  • Hexadecimal
  • Binary
  • HTML entity numbers

Syntax

String.encodeAs(type);

Parameters

Parameter Description
type A string value which determines the encoding method. Possible values are : decimal, hex, binary, and entity. Defaults to decimal conversion if left undefined.
Clone this wiki locally