In AskiaScript, a string variable contains characters (note that it may also be empty).
In this topic:
To create a string variable, assign a string value (or an empty string) between double quotes (").
The end of the string is the final non-escaped double quote character.
Returns the length of the string (number of characters)
Returns a Number.
dim my_string = "abcd" my_string.length ' => 4
dim my_empty_string = "" my_empty_string.length ' => 0
Compares two strings using the local language.
text is the same.text is not found.
dim s = "gfhi"
s.Collate("abcde") ' => positive value
dim s = "abcde"
s.Collate("abcde") ' => 0
dim s = "Fussballmanager"
s.Collate("fußballmanager",1,"DEU") ' => 0
dim s = "Fussballmanager"
s.Collate("fußballmanager",2,1031) ' => 1
Compares a string against an array of strings, using the locale language.
Returns an array of numbers to indicate which strings have been matched.
dim s = "abcde"
s.CollateAny({"ab"; "abcded"; "fghi"}) ' => returns {2}
dim s = "Fussballmanager"
s.CollateAny({"footbal" ; "fussballmanager"; "fußballmanager"},1,"DEU") ' => returns {2;3}
Calculates the distance between two strings using the Damerau-Levenshtein Distance. This distance is useful when finding spelling errors.
Returns a number.
dim s = "abcde"
s.DLDistance("abce") ' => 1
dim s = "abcde"
s.DLDistance("abdce") ' => 1
dim s = "abcde"
s.DLDistance("abcde") ' => 0
Searches the text in the string and returns its position (based 1).
text is not found.
dim s = "abcdefghijk"
s.IndexOf("BcD") ' => 2
dim s = "abcdefghijk"
s.IndexOf("lmn") ' => DK (not found)
dim s = "abcdefghijk"
s.IndexOf("CDE", true) ' => DK (not found with the case sensitive flag)
Verifies that the string is formatted as a valid date, using:
format parameter is used).Returns a Boolean.
dim s = "22/03/2011" s.IsDate() ' => True
dim s = "22##03##2011" s.IsDate() ' => False
dim s = "22##03##2011"
s.IsDate("dd##MM##yyyy") ' => True
Verifies that the string is formatted as a valid email address (x@x.xxx).
Returns a Boolean.
dim s = "askia@askia.com" s.IsEmail() ' => True
dim s = "askia#askia.com" s.IsEmail() ' => False
Verifies that the string matches the specified format, using a regular expression.
Returns a Boolean.
dim email = "askia@askia.com"
email.IsMatch("w+@[a-zA-Z_]+.[a-zA-Z]{2,3}$")
Regular expression to valid that a string contains the uk phone number pattern
+(##) ### ### #### or 00## ### ### ####
dim rgUkPhone = "(+|00)s*d{2}(s?d{3}){2}s?d{4}"
'
("0044 207 689 5492").IsMatch(rgUkPhone) ' => true
("00442076895492").IsMatch(rgUkPhone) ' => true
("+44 207 689 5492").IsMatch(rgUkPhone) ' => true
("+442076895492").IsMatch(rgUkPhone) ' => true
("207 689 5492").IsMatch(rgUkPhone) ' => false
("44 207 689 5492").IsMatch(rgUkPhone) ' => false
("442076895492").IsMatch(rgUkPhone) ' => false
("Before it was 00 44 204 689 5492 and
now it's 00 44 207 689 5492").IsMatch(rgUkPhone)
' => true
("My contact numbers are:
+44 207 689 5492
or
0044 207 123 4567").IsMatch(rgUkPhone) ' => true
Same regular expression as above, but tests if the string only contains the UK phone number and nothing else.
dim rgOnlyUkPhone = "^(+|00)s*d{2}(s?d{3}){2}s?d{4}$"
'
("+44 207 689 5492").IsMatch(rgOnlyUkPhone) ' => true
("0044 207 689 5492").IsMatch(rgOnlyUkPhone) ' => true
("Before it was 00 44 204 689 5492
and now it's 00 44 207 689 5492").IsMatch(rgOnlyUkPhone)
' => false
Verifies that the string is formatted as a valid number.
Returns a Boolean.
dim s = "abcde" s.IsNumber() ' => 0
dim s = "123.99" s.IsNumber() ' => True
dim s = "123,99" s.IsNumber() ' => True
dim s = "123,999.32" s.IsNumber() ' => False thousand separators not supported
Verifies that the string is formatted as a valid UK Postcode.
Returns a Boolean.
dim s = "L1 4AB" s.IsUKPostCode() ' => True
dim s = "L4B1C12" s.IsUKPostCode() ' => False
Extracts part of the string, starting at the left-hand end.
Returns a String.
If the specified length is higher than the length of the string, it returns the entire string.
dim s = "abcde" s.Left(3) ' => "abc"
dim s = "abcde" s.Left(10) ' => "abcde"
Verifies that the string matches the specified format, using a regular expression from the library.
Parameters
dim s = "askia@askia.com"
s.QuickMatch("IsEmail") ' => True
Returns a new string and replaces the specified pattern with the specified replacement.
Returns a String.
dim s = "Hello world!"
s = s.Replace("Hello", "Hi")
' => "Hi world!"
dim abc = "abc"
abc = abc.Replace("A", "X")
' => "Xbc"
dim case = "Sensitive"
case.Replace("sensitive", "Insensitive", true)
' => "Sensitive" Doesn't change
dim case = "Sensitive"
case.Replace("sensitive", "Insensitive",false)
' => "Insensitive"
Returns a new string and replace the first match of the specified regexp pattern by the specified replacement. By default the text replacement is case sensitive. If there is 'i' (insensitive) modifier in the third parameter the text replacement is not case sensitive. If there is 'g' (global) modifier in the third parameter the replacement is done on all matches.
Returns a String.
dim case = "Sensitive"
case = case.ReplaceRegexp("s.*n", "Insen")
' => "Sensitive" Doesn't change
dim s = "Sensitive"
s = s.ReplaceRegexp("s.*n", "Insen", "i")
' => "Insensitive"
dim case = "abcdef"
case = case.ReplaceRegexp("[a-e]", "X")
' => "Xbcdef" The replacement is done only on the first match
dim case = "abcdef"
case = case.ReplaceRegexp("[a-e]", "X", "g")
' => "XXXXXf" The replacement is done on all matches
dim case = "abcdef"
case = case.ReplaceRegexp("[A-E]", "X", "g")
' => "abcdef" Doesn't change (case sensitive)
dim case = "abcdef"
case = case.ReplaceRegexp("[A-E]", "X", "gi")
' => "XXXXXf" The replacement is done on all matches and case insensitive
Extracts a section of the string, starting from the right-hand end.
Returns a Boolean.
If the specified length is higher than the length of the string, it returns the entire string.
Parameters
dim s = "abcde" s.Right(3) ' => "cde"
dim s = "abcde" s.Right(10) ' => "abcde"
Splits the string into an array of strings.
Returns a StringArray.
dim s = "1,3,5,7,9"
s.Split() ' => {"1"; "3"; "5"; "7"; "9"}
dim s = "a|b|c|d|e"
s.Split("|") ' => {"a"; "b"; "c"; "d"; "e"}
dim s = "a|b|c|d|e"
s.Split("|")[2] ' => "b"
Splits the string into an array of numbers.
Returns a NumArray.
dim s = "1,3,5,7,9"
s.SplitToNumbers() ' => {1; 3; 5; 7; 9}
dim s = "1|3|5|7|9"
s.SplitToNumbers("|") ' => {1; 3; 5; 7; 9}
dim s = "1|3|5|7|9"
s.SplitToNumbers("|")[2] ' => 3
dim s = "1|3|toto|7|tata|12"
s.SplitToNumbers("|") ' => {1; 3; DK; 7; DK; 12}
Extracts a sub-string starting at the specified index (based 1), with a given length.
Returns a String.
length is higher than the length of the string, it returns the end of the string.start position is higher than the length of the string, it returns an empty string.dim s = "abcde" s.Substring(2, 3) ' => "bcd"
dim s = "abcde" s.Substring(2) ' => "bcde"
dim s = "abcde" s.Substring(3, 10) ' => "cde"
dim s = "abcde" s.Substring(10, 2) ' => ""
Returns a new string in ASCII format. This is useful for converting UNICODE characters to ASCII.
For example:
“234”.ToAscii()
returns "234".
Converts the string to a date, using:
format parameter is used).Returns DK when the string cannot be converted to a date.
Returns a Date.
dim s = "22/03/2011" s.ToDate() ' => #22/03/2011#
dim t = "2011-03-22"
t.ToDate("yyyy-MM-dd") ' => #22/03/2011#
dim invalidDate = "Hello world!" invalidDate.ToDate() ' => DK (Invalid date)
Attempts to convert the string, which represents a colour (hexa, rgb or rgba), to its Hexadecimal equivalent string.
Returns a String.
See also: String as color.
dim s = "#ff0000" ' Red color in Hexa s.ToHexa() ' => "#ff0000" ' Remain the same
dim s = "0,255,0,0.5" ' Green semi-transparent color in RGBA s.ToHexa() ' => "#00ff00" ' Drop the alpha the green color ' will be fully opaque
dim s = "0,0,255" ' Blue color in RGB s.ToHexa() ' => "#0000ff"
dim s = "Not a color string" s.ToHexa() ' => "" ' fail to convert
dim s = "red" ' Named color is not interpreted s.ToHexa() ' => ""
Returns a new string in lowercase.
Returns a String.
dim s = "Hello World!" s = s.ToLowerCase() ' => "hello world!"
Converts the string to a number, if possible.
Returns a Number.
Returns DK when the string cannot be converted to number.
dim s = "123" s.ToNumber() ' => 123
dim s = "123.99" s.ToNumber() ' => 123.99
dim s = "123,456" s.ToNumber() ' => 123.456
dim s = "123,456.789" s.ToNumber() ' => DK (not a valid number) ' The thousand separator generate an exception
Attempts to convert a string representing a colour (hexa, rgb or rgba) to its RGB equivalent string.
Returns a String.
See also: String as color.
dim s = "#ff0000" ' Red color in Hexa s.ToRGB() ' => "255,0,0"
dim s = "0,255,0,0.5" ' Green semi-transparent color in RGBA s.ToRGB() ' => "0,255,0" ' Drop the alpha the green color ' will be fully opaque
dim s = "0,0,255" ' Blue color in RGB s.ToRGB() ' => "0,0,255" ' Remain the same
dim s = "Not a color string" s.ToRGB() ' => "" ' fail to convert
dim s = "red" ' Named color is not interpreted s.ToRGB() ' => ""
Attempts to convert the string, which represents a colour (hexa, rgb or rgba), to its RGBA equivalent string.
Returns a String.
See also: String as colour.
dim s = "#ff0000" ' Red color in Hexa s.ToRGBA() ' => "255,0,0,1" ' Full opaque red color
dim s = "0,255,0,0.5" ' Green semi-transparent color in RGBA s.ToRGBA() ' => "0,255,0,0.5" ' Remain the same
dim s = "0,0,255" ' Blue color in RGB s.ToRGBA() ' => "0,0,255,1" ' Full opaque blue
dim s = "Not a color string" s.ToRGBA() ' => "" ' fail to convert
dim s = "red" ' Named color is not interpreted s.ToRGBA() ' => ""
Returns a new string in uppercase.
Returns a String.
dim s = "Hello world!" s = s.ToUpperCase() ' => "HELLO WORLD!"
Returns a new string without the trailing spaces before and after the string.
Returns a String.
dim s = " spaces before/after " s = s.Trim() ' => "spaces before/after"
Returns an identical string.
Returns a String.
dim s = "Hello world!" s.ToString() ' => "Hello world!"
Always returns "string".
Returns a String.
dim s = "abc" s.TypeOf() ' => "string"
| Name | Symbol / Expression | Description | Example |
|---|---|---|---|
| Equal | = |
Tests whether two strings are equal. Returns a boolean. To use this operator to perform a comparison, the condition should be between brackets, or else it will be considered an assignment operator
|
dim i = "MyText" (i = "MyText") ' => True (i = "mytext") ' => False |
| Different | <> |
Tests whether two strings are not equal. Returns a boolean. |
dim i = "MyText" i <> "MyText" ' => False i <> "mytext" ' => True |
| Concatenate | + |
Concatenates strings of characters. Returns a string. |
dim i = "MyFirstText" dim j = " is nice" i + j ' => MyFirstText is nice |
A string could represent a colour in RGB, RGBA or Hexa format.
"R, G, B"where R, G and B each represent a number from 0 to 255 (0 not apply, 255 fully apply). Trailing white spaces between values are ignored.
"R, G, B, A"where R, G and B each represent a number from 0 to 255 (0 not apply, 255 fully apply) and the A (alpha channel) is a value between 0 and 1 (0 fully transparent, 1 fully opaque). Trailing whitespaces between value are ignored.
"#RGB"where R, G and B each represent a hexadecimal value from 00 to FF (00 not apply, FF fully apply). The '#' symbol is required.