Lasso Soft Inc. > Home

[ String ]

Type

[string] creates a new string object. String objects exist as a series of Unicode characters in the UTF-32 encoding.

Empty strings can be created by calling this method with no parameters. This is the same as using an empty string literal: '', "" or ``.

A bytes object can be converted into a string by passing it to the [string] method. By default, the bytes object is assumed to contain UTF-8 characters. An optional character encoding name (e.g. 'ISO-8859-1') can be passed as the second parameter. In this case, the bytes object will be converted to Unicode using that encoding. If an unknown or unsupported character encoding name is given, a failure will be generated.

If an existing string object is passed to the [string] method, a copy of the string is generated and returned.

Any other object can be converted into a string by passing it to the [string] method. In this case, it is equivalent to calling the ->asString() method on the given object. Objects which do not provide custom ->asString() implementations are converted using the following conventions:

  • Integer and decimal objects are converted to their base ten string representation
  • A null or void object is converted into an empty string
  • Boolean objects are converted into either 'true' or 'false'
  • Date and duration objects are formatted in the same manner as when calling their ->format() methods
  • Objects which contain other objects, such as arrays, maps or pairs, will, in general, output the name of the object's type, followed by a set of parentheses surrounding the comma separated list of each contained element
    • Each contained element is itself converted into a string by calling the ->asString() method
  • Any object may provide a custom ->asString() method and so the result of converting an object into a string may vary
  • Any object not providing its own ->asString() method will have generated a string containing only the object's type name
  • Syntax
  • Methods
  • Traits
string
string('value')
string(#variable)
string(#someBytes, 'ISO-8859-1')
Has methods:
Examples
  • Beginner

To convert an integer into a string:

Use the [string] method. The following example performs a string operation on a set of numbers by converting them to string values before applying the concatenation symbol (+) to the results.

Code

string(1) + string(1)

Result

11

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft