Text in Lasso is stored and manipulated using the string data type or the [String] methods. This chapter details the symbols and methods that can be used to manipulate string values.
Information about regular expression can be found in the Regular Expressions chapter which follows. The string type is often used in conjunction with the bytes type to convert binary data between different character encodings (UTF-8, ISO-8859-1). See the Bytes chapter for more information about the bytes type.
Many Lasso methods are dedicated to outputting and manipulating text. Lasso is used to format text-based HTML pages or XML data for output. Lasso is also used to process and manipulate text-based HTML form inputs and URLs. Text processing is a central function of Lasso.
As a result of this focus on text processing, the string data type is the primary data type in Lasso. When necessary, all values are cast to string before subsequent tag or symbol processing occurs. All values are cast to string before they are output into the HTML page or XML data which will be served to the site visitor.
There are three types of operations that can be performed directly on strings.
Symbols can be used to perform string calculations within Lasso methods or to perform assignment operations within LassoScripts.
['The' + ' ' + 'String']
The String
['The String'->Substring(4, 6)]
String
[String_LowerCase('The String')]
the string
Each of these methods is described in detail in the sections that follow. This guide contains a description of every symbol and method and many examples of their use. The Lasso Reference is the primary documentation source for Lasso symbols and method. It contains a full description of each symbol and tag including details about each parameter.
Lasso 9 supports the processing of Unicode characters in all string methods. The escape sequence \u... can be used with 4, or 8 hexadecimal characters to embed a Unicode character in a string. For example \u002F reprsents a / character, \u0020 represents a space, and \u0042 represents a capital letter B. The same type of escape sequence can be used to embed any Unicode character \u4E26 represents the Traditional Chinese character .
Lasso also supports common escape sequences including \r for a return character, \n for a new-line character, \r\n for a Windows return/new-line, \f for a form-feed character, \t for a tab, and \v for a vertical-tab.
Values can be cast to the string data type automatically in many situations or they can be cast explicitly using the [String] method.
Casts a value to type string. Requires one value which is the data to be cast to a string. An optional second parameter can be used when casting byte streams to a string and specified what character set should be used to translate the byte stream (defaults to UTF-8).
['String ' + 123] String 123
The following example shows how a variable that contains the integer 123 is automatically cast to a string.
[var(Number = 123)] ['String ' + var(Number)] String 123
[(Array: 'One', 'Two', 'Three')]
(Array: (One), (Two), (Three))
[(Map: 'Key1'='Value1', 'Key2'='Value2')]
(Map: (Key1)=(Value1), (Key2)=(Value2))
[(Pair: 'Name'='Value')]
(Pair: (Name)=(Value))
More information can be found in the Arrays and Maps chapter.
[Field: 'Age']
21
[String_Length: (Field: 'Age')]
2
The following example shows a math calculation and the integer operation result 579. The next line shows the same calculation with string parameters and the string symbol result 123456.
[123 + 456] 579
[(String: 123) + (String: 456)] 123456
[(String: ('dog' == 'cat'))] false
[Field: 'Age'] 21
[(String: (Field: 'Age'))->Size] 2
[String: $myByteStream, 'iso-8859-1']
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft