Class: StringReader

Represents a reader which will wrap string content as a channel.

Constructor

Constructs a channel to read string.

init (string content, string encoding)
  • content string
  • The content, which should be written

  • encoding string "UTF-8"
  • Encoding of the characters of the content

Methods

readJson

Reads string as JSON using the reader.

readXml

Reads a string as XML using the reader.

readChar

Reads the characters from the given string.

close

Closes the string reader.

readJson

function readJson() returns json | Error
Isolated Function

Reads string as JSON using the reader.

1io:StringReader reader = new("{\"name\": \"Alice\"}");
2json|io:Error? person = reader.readJson();

Return Type

(json | Error)

JSON or else an io:Error if any error occurred

readXml

function readXml() returns xml | Error?
Isolated Function

Reads a string as XML using the reader.

1io:StringReader reader = new("<Person><Name>Alice</Name></Person>");
2xml|io:Error? person = reader.readXml();

Return Type

(xml | Error?)

XML or else an io:Error if any error occurred

readChar

function readChar(int nCharacters) returns string | Error?
Isolated Function

Reads the characters from the given string.

1io:StringReader reader = new("Some text");
2string|io:Error? person = reader.readChar(4);

Parameters

  • nCharacters int
  • Number of characters to be read

Return Type

(string | Error?)

String or else an io:Error if any error occurred

close

function close() returns Error?
Isolated Function

Closes the string reader.

1io:Error? err = reader.close();

Return Type

(Error?)

An io:Error if could not close the channel or else ()