Object - io : StringReader

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

Constructor

__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

Reads string as JSON using the reader.
Reads a string as XML using the reader.
Reads the characters from the given string.
Closes the reader.

readJson

()

returns json | Error

Reads string as JSON using the reader.

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

  • Return Type

    (json | Error)
  • JSON or else io:Error if any error occurred

readXml

()

returns xml | Error | ()

Reads a string as XML using the reader.

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

  • Return Type

    (xml | Error | ())
  • XML or else io:Error if any error occurred

readChar

(int nCharacters)

returns string | Error | ()

Reads the characters from the given string.

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

Parameters

  • nCharacters int
  • Number of characters to be read

  • Return Type

    (string | Error | ())
  • String or else io:Error if any error occurred

close

()

returns Error?

Closes the reader.

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

  • Return Type

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