Working with Text in Airscript
Last updated
Was this helpful?
Last updated
Was this helpful?
The type in Airscript is used to hold written text that might be displayed to the user in a . The text type is also used when capturing information from a user such as a name, an address, or phone number. In addition to using the Text type to store real-world information, the Text type is also often used to store data used by computers, such as a unique identifier or the status of an ongoing sales opportunity. Airkit provides a suite of useful utilities to help work with data of this nature.
Note: In Airscript, as in many other programming languages., a particular instance of the text type is often referred to as a String.
To create Text (a string), enclose the text with the double-quote character (")
For the majority of use cases, it is useful to think of a string as a sequence of characters such as a, b, or even special characters such as -, %, or really any other character that might be needed. The number of characters in a string can be obtained with the function. For example, the length of the string "Hello world" is 12.
Note: The definition of a character may not always be what you expect, for example, the "Slightly Smiling Face" emoji (🙂) as well as many non-English characters are actually made up of two or more characters. See for more information.
There are a number of routine operations needed for dealing with strings.
When accepting input from a user you may want to remove extra whitespace, for example, if the user enters an extra space at the end of their name you will likely want to remove it so that you store their name as "John Smith" rather than "John Smith ". The function removes spaces, tabs, newlines, and other whitespace from the beginning and end of a string.
There are times that you may want to repeat a given string a certain number of times, for example repeating the string "abc" three times to get the string "abcabcabc". See the and functions for this.
It is also fairly routine to ensure a string contains only lowercase or uppercase characters. The and functions will do just that.
A substring is a smaller string contained inside a larger string. Both "Hello", and "world" are substrings of the string "Hello world". The function extracts substrings from a larger string using a starting and ending position inside the string.
It is very common for external systems to encode different types as strings. Airkit provides a set of functions to convert between other types and strings.
NULL, Boolean, Number, String, Object List
JSON
JSON String
NULL, Boolean, Number, String, Object List
Number
Configurable
Configurable
Number
Phone Number
E-164 String ("+15551234567")
E-164 String ("+15551234567")
Phone Number
Datetime
RFC 3339 timestamp (Configurable)
RFC 3339 timestamp (Configurable)
Datetime
Date
RFC 3339 timestamp (Configurable)
RFC 3339 timestamp (Configurable)
Date
Time
RFC 3339 timestamp (Configurable)
RFC 3339 timestamp (Configurable)
Time
Although you may not always know ahead of time the position of a substring. In these cases use the function to find the beginning of a substring. If the result is -1 it means the substring was not found.
You may be interested in whether one string is alphabetically smaller than another. The function will determine this by returning a negative number if the first string is smaller than the second, 0 if the strings are the same, and a positive number if the first string is larger than the second
The function will combine two or more strings.
In order to replace a substring with another use or . The function will replace the first occurrence of the substring, while the function will replace any number of occurrences.
Another way to combine strings is using the function to combine multiple strings with a particular separator.
The function is the opposite of the function, in that it turns a string into multiple strings by splitting on a separator.