Module: Toybox.StringUtil

Overview

The StringUtil module contains String utility functions

Since:

API Level 1.3.0

Classes Under Namespace

Classes: InvalidHexStringException

Constant Summary

CharacterEncoding

Name Value Since Description
CHAR_ENCODING_UTF8 0

API Level 3.0.0

Representation

Name Value Since Description
REPRESENTATION_STRING_BASE64 0

API Level 3.0.0

REPRESENTATION_STRING_HEX 1

API Level 3.0.0

REPRESENTATION_STRING_PLAIN_TEXT 2

API Level 3.0.0

REPRESENTATION_BYTE_ARRAY 3

API Level 3.0.0

Instance Method Summary collapse

Instance Method Details

charArrayToString(charArray as Array<Char>) as String

Given an Array of Char objects, return the String equivalent

Parameters:

  • charArray(Array)

    An Array of Char objects

Returns:

  • String

    The String representation of the input Array

Since:

API Level 1.3.0

convertEncodedString(input as String or ByteArray, options as { :fromRepresentation as Representation, :toRepresentation as Representation, :encoding as CharacterEncoding }) as String or ByteArray

Convert a String or ByteArray representation to a String or ByteArray representation whose underlying byte format corresponds to the provided input options.

Parameters:

  • input(String, ByteArray)

    Input that needs to be converted.

  • options(Dictionary)
    • :fromRepresentation(Number)

      Required. A REPRESENTATION_* enum value indicating the representation from which the input should be converted.

    • :toRepresentation(Number)

      Required. A REPRESENTATION_* enum value indicating the representation to which the input should be converted.

    • :encoding(Number)

      A CHAR_ENCODING_* value indicating the String encoding to use when generating a hex string or ByteArray when either the fromRepresentation or toRepresentation is set to REPRESENTATION_STRING_PLAIN_TEXT. Defaults to CHAR_ENCODING_UTF8 if not specified.

Returns:

  • String, ByteArray

    The converted String or ByteArray based on the provided options

Since:

API Level 3.0.0

Throws:

encodeBase64(string as String) as String

Encodes a String in base64

Parameters:

  • string(String)

    The string to encode

Returns:

  • String

    A base64 encoded String

Since:

API Level 1.3.0

utf8ArrayToString(utf8Array as Array<Number> or ByteArray) as String

Given an Array of UTF-8 bytes, return the String equivalent

Parameters:

  • utf8Array(Array)

    An Array of UTF-8 bytes

Returns:

  • String

    The String representation of the input Array

Since:

API Level 1.3.0


Generated Apr 22, 2021 10:10:32 AM