Abinitio Functions
A>I In-built Functions
- re_get_match : Returns the first and longest string in a target string that matches a regular expression.
e.g., re_get_match("man on the moon", "oo") --> "oo"
e.g., re_get_match("1234 Milldale Ave.", "[a-zA-Z]+") --> "Milldale"
e.g., re_get_match("1234 Milldale Ave.", "[0-9]+") --> "1234"
- re_get_matches : Returns, from a target string, a vector of substrings that match the first instance of a regular expression containing upto a nine capturing.
e.g., re_get_matches(str = "212-555-1212", pattern = "(\\d{3})[-]?(\\d{3})[-]?(\\d{4})")
Output --> [ vector
"212-555-1212",
"212",
"555",
"1212" ]
e.g., re_get_matches("222Milldale12Yonge", "([0-9]+)([[:alpha:]]+)")
Output --> [ vector
"222Milldale",
"222",
"Milldale" ]
In above example re_get_matches returns matches for the three specified capturing groups
a sequence containing one or more numeric characters and one or more alphabetic characters,
followed by a sequence containing one or more numeric characters, followed by a sequence
containing one or more alphabetic characters.
e.g., re_index(str = "man on the moon", pattern = "oo") --> 13
e.g., re_index("1234 Milldale Ave.", "[a-zA-Z]+") --> 6
e.g., re_index("1234 Milldale Ave." , "[0-9]+") --> 1
e.g., re_index("Fourteen 35th St.' , "[^0-9]+") --> 1
e.g., re_get_matches("222Milldale12Yonge", "([0-9]+)([[:alpha:]]+)", 4)
Output --> [ vector
"12Yonge",
"12",
"Yonge" ]
In above example offset value is 4 so re_get_matches will start searching for matches after index 4 of the target string
- e.g., is_null(re_get_matches("", "[0-9]")) --> 1
- e.g., is_null(re_get_matches("Fourteen 35th St.", "^[0-9]")) --> 1
- re_index : Returns the index of the first character of a substring of a target string that matches a specified regular expression.
e.g., re_index(str = "man on the moon", pattern = "oo") --> 13
e.g., re_index("1234 Milldale Ave.", "[a-zA-Z]+") --> 6
e.g., re_index("1234 Milldale Ave." , "[0-9]+") --> 1
e.g., re_index("Fourteen 35th St.' , "[^0-9]+") --> 1
- re_split : Splits a string into substrings using a specified regular expression
Output --> [ vector
"abc",
"def" ]
e.g., re_split("ab\t\tcd\nef", "[[:space:]]+")
Output --> [ vector
"ab",
"cd",
"ef" ]
String Functions :
- string_prefix : Returns a substring that starts at the beginning of the parent string and is of the specified length.
Syntax : string string_prefix(string str, integer length)
e.g., : string_prefix("114 Willingham Road Keswick", 30)
Output - "114 Willingham Road Keswick"
e.g., : string_prefix("114 Willingham Road Keswick", -20)
Output : ""
- string_compare : Returns a number representing the result of comparing two strings.
Syntax : long string_compare(string str1, string str2)
The string_compare function returns the following after comparing the lexicographic order of str1 and str2:
-1 if the first argument is ordered before the second
0 if the arguments are equal
1 if the first argument is ordered after the second
NULL if either argument evaluates to NULL
e.g., string_compare(str1 = "abcd", str2 = "abcd") --> 0
string_compare returns 0 because the specified strings have an identical lexicographic order
e.g., string_compare("abc","ab")
string_compare("abc","a")
string_compare("abc","")
Output : 1
Here the longer string (first argument) is ordered after the shorter string (second argument), which contains characters that partially match those in the longer string
e.g., string_compare("aaaa", "bbbb") --> -1
string_compare returns -1 because the lexicographic order of "aaaa" comes before that of "bbbb"
e.g., string_compare("bbbb", "aaaa") --> 1
string_compare returns 1 because the lexicographic order of "bbbb" comes after that of "aaaa"
e.g., string_compare("aaaa", "a") --> 1
string_compare returns 1 because the lexicographic order of "aaaa" comes after that of "a"
e.g., string_compare("AAAA", "aaaa") --> -1
string_compare returns -1 because the lexicographic order of "AAAA" comes before that of "aaaa" (assuming ASCII as the default character set)
e.g., string_compare((ebcdic string(4))"AAAA",(ebcdic string(4))"aaaa")
Output : 1
string_compare returns 1 because the lexicographic order of EBCDIC "AAAA" comes after that of EBCDIC "aaaa"
e.g., string_compare((ebcdic string(4))"AAAA",(ascii string(4))"aaaa")
Output : -1
string_compare compares the same string represented, respectively, in EBCDIC and ASCII, on a platform whose native character set is ASCII, as follows
- string_concat : Concatenates multiple string arguments and returns the results as a NUL-delimited string.
Syntax : string string_concat(string str [ , string str ... ] )
e.g., string_concat(str1 = "abcd", str2 = "efgh")
Output : "abcdefgh"
e.g., string_concat("John", " ", "Smith")
Output : "John Smith"
e.g., string_concat(U"abc", U"\u0091")
Output : "abc\u0091"
- string_downcase : Returns a string with any uppercase letters converted to lowercase.
Syntax : string string_downcase(string str)
e.g., string_downcase("abcXYZ")
Output : "abcxyz"
e.g., string_downcase("heLlO, WOrlD! #HasHTaG")
Output : "hello, world! #hashtag"
- string_filter : Compares the contents of two strings, then returns a string containing characters that appear in both of them.
Syntax : string string_filter(string str, string filter_str)
e.g., string_filter(str = "AXBYCZ", filter_str = "ABCDEF")
Output : "ABC"
e.g., string_filter("023#46#13", "0123456789")
Output : "0234613"
- string_filter_out : Compares two input strings, then returns a string containing characters that appear in one string but not in the other.
Syntax : string string_filter_out(string str, string filter_str)
e.g., string_filter_out(str = "AXBYCZ", filter_str = "ABCDEF")
Output : "XYZ"
e.g., string_filter_out("ABCXYZCBA", "XYZ")
Output : "ABCCBA"
e.g., string_filter_out("Apt. #2", ".#,%")
Output : "Apt 2"
- string_index : Returns the index of the first character of the first occurrence of a string within another string.
Syntax : long string_index(string str, string find_str [ , integer offset ] )
e.g., string_index(str = "to be or not to be", find_str = "be")
Output : 4
e.g., string_index(U"abcdefghi", U"def")
Output : 4
e.g., string_index("rstuvwxyz", "abc")
Output : 0
e.g., string_index("qwerty", "")
Output : 1
e.g., string_index("AxxA", "A", 1)
Output : 4
- string_join : Concatenates vector string elements into a single string.
Syntax : string(int) string_join(string[integer] str_vec, string sep_str)
e.g., string_join(str_vec = [vector "quick", "brown", "fox"], sep_str = " ")
Output : "quick brown fox"
e.g., string_join([vector "a", "bc", "def"], "")
Output : "abcdef"
e.g., string_join(string_split("at a glance", " "), "!!")
Output : "at!!a!!glance"
- string_length : Returns the number of characters in a string.
Syntax : long string_length(string str)
e.g., string_length("")
Output : 0
e.g., string_length("abc")
Output : 3
e.g., string_length("abc ")
Output : 6
- string_like : Tests whether a string matches a specified pattern.
Syntax : long string_like(string str, string pattern [ , string(1) escape_char ] )
e.g., string_like(str = "abcdef ", pattern = "abc%")
Output : 1
e.g., string_like("abcdef", "abc_")
Output : 0
e.g., string_like("abcdef", "abc_ef")
Output : 1
e.g., string_like("abcdef%", "%cdef?%", "?")
Output : 1
- string_lpad : Returns a string of a specified length, left-padded with a given character.
Syntax : string string_lpad(string str, integer length [ , string pad_char ] )
e.g., string_lpad(str = "abc", length = 5)
Output : " abc"
e.g., string_lpad("abc", 5, "#")
Output : "##abc"
e.g., string_lpad("abcdefgh", 5, "#")
Output : "abcdefgh"
e.g., string_lpad(U"ab", 3, U"\u0099")
Output : "\u0099ab"
e.g., string_lpad("abc",5,"") // WRONG
Output : Error will be prompted
- string_lrepad : Returns a string of a specified length, trimmed of leading and trailing blanks, and left-padded with a given character.
Syntax : string string_lrepad(string str, integer length [ , string pad_char ] )
e.g., string_lrepad(str = "abc", length = 5)
Output : " abc"
e.g., string_lrepad(" abc ", 5, "#")
Output : "##abc"
e.g., string_lrepad("abcdefgh", 5, "#")
Output : "abcdefgh"
e.g., string_lrepad(" abc ",4,"") // WRONG
- string_lrtrim : Returns a string trimmed of leading and trailing blank characters.
Syntax : string string_lrtrim(string str)
e.g., string_lrtrim(" abc ")
Output : "abc"
e.g., string_lrtrim("John")
Output : "John"
- string_ltrim : Returns a string trimmed of leading blank characters.
Syntax : string string_ltrim(string str)
e.g., string_ltrim(" abc")
Output : "abc"
e.g., string_ltrim(" abc ")
Output : "abc "
e.g., string_ltrim("John")
Output : "John"
e.g., string_ltrim(U"\u2000Joe")
Output : "Joe"
- string_pad : Returns a string of a specified length, right-padded with a given character.
Syntax : string string_pad(string str, integer length, string pad_char=" ")
e.g., string_pad(str = "abc", length = 5)
Output : "abc "
e.g., string_pad("abc", 5, "#")
Output : "abc##"
e.g., string_pad("abcdefgh", 5, "#")
Output : "abcdefgh"
e.g., string_pad("abc", 5, "") // WRONG
- string_repad : Returns a string of a specified length, trimmed of any leading and trailing blanks, and right-padded with a given character.
Syntax : string string_repad(string str, integer length [ , string pad_char ] )
e.g., string_repad(str = "abc", length = 5)
Output : "abc "
e.g., string_repad(" abc ", 5, "#")
Output : "abc##"
e.g., string_repad("abcdefgh", 5, "#")
Output : "abcdefgh"
e.g., string_repad(" abc ",4,"") // WRONG
- string_prefix : Returns a substring that starts at the beginning of the parent string and is of the specified length.
Syntax : string string_prefix(string str, integer length)
e.g., string_prefix(str = "114 Willingham Road Keswick", length = 20)
Output : "114 Willingham Road "
e.g., string_prefix("114 Willingham Road Keswick", 30)
Output : "114 Willingham Road Keswick"
e.g., string_prefix("114 Willingham Road Keswick", -20)
Output : ""
- string_replace : Returns a string after replacing one substring with another.
Syntax : string string_replace(string str, string find_str, string replace_str [ , integer offset ] )
e.g., string_replace(str = "a man a plan a canal", find_str = "an", replace_str = "ew")
Output : "a mew a plew a cewal"
e.g., string_replace("a man a plan a canal", "ship", "boat")
Output : "a man a plan a canal"
e.g., string_replace("abcde", "", "*")
Output : "*a*b*c*d*e*"
e.g., string_replace(U"ab", U"b", U"\u0099")
Output : "a\u0099"
e.g., string_replace("AxxAAA", "A", "z", 1)
Output : "Axxzzz"
- string_replace_first : Returns a string after replacing the first occurrence of one substring with another.
Syntax : string string_replace_first(string str, string find_str, string replace_str [ , integer offset ] )
e.g., string_replace_first(str = "a man a plan a canal", find_str = "an", replace_str = "ew")
Output : "a mew a plan a canal"
e.g., string_replace_first("AxxAAA", "A", "Z", 1)
Output : "AxxZAA"
- string_rindex : Returns the index of the first character of the last occurrence of a string within another string.
Syntax : long string_rindex(string str, string find_str [ , integer offset ] )
e.g., string_rindex(str = "to be or not to be", find_str = "be")
Output : 17
e.g., string_rindex("abcdefghi", "def")
Output : 4
e.g., string_rindex("John Smith", "&")
Output : 0
e.g., string_rindex("rstuvwxyz", "abc")
Output : 0
e.g., string_rindex("qwerty", "")
Output : 7
e.g., string_rindex("AxxA", "A", 1)
Output : 1
- string_split : Returns a vector consisting of substrings of a specified string.
Syntax : string(int)[int] string_split(string str, string sep_str)
e.g., string_split(str = "quick,brown,fox", sep_str = ",")
Output : [vector
"quick", "brown", "fox"]
e.g., string_split("what a bad day dad had", "#")
Output : [vector
"what a bad day dad had"]
e.g., string_split("xoanon", "x")
Output : [vector
"", "oanon"]
e.g., string_split("flax", "x")
Output : [vector
"fla", ""]
e.g., string_split("who? what? where? ","? ")
Output : [vector
"who", "what", "where", ""]
- string_split_no_empty : Called like and behaves like string_split, but excludes empty strings from its output.
e.g., string_split("abc\ndef\n","\n")⇒ [vector
"abc", "def", ""]
e.g., string_split_no_empty("abc\ndef\n","\n")
⇒ [vector "abc", "def"]
- string_trim : Returns a string trimmed of trailing blank characters.
Syntax : string string_trim(string str)
e.g., string_trim("abc ")
Output : "abc"
e.g., string_trim("John")
Output : "John"
e.g., string_trim(U"\u2000Joe")
Output : "\u2000Joe"
e.g., string_trim(U"Joe\u2000")
Output : "Joe"
- string_upcase : Returns a string with any lowercase letters converted to uppercase.
Syntax : string string_upcase(string str)
e.g., string_upcase("abcXYZ")
Output : "ABCXYZ"
e.g., string_upcase("heLlO, WOrlD! #HasHTaG")
Output : "HELLO, WORLD! #HASHTAG"
- string_to_hex : Returns a string of hexadecimal digits (0-9 a-f) in which each pair of characters represents the value of one byte of the input void or string object. Converts a void or string object to a printable hexadecimal string.
Syntax : string string_to_hex(string or void value)
e.g., m_eval 'string_to_hex("abc")'
Output : "616263"
e.g., m_eval 'string_to_hex(hash_SHA256("hello world"))'
Output : "B94D27B9934D3E08A52E52D7DA7DABFAC484EFE37A5380EE9088F7ACE2EFCDE9"
The above example shows how to use the hash_SHA256 function to convert the "hello world" string to a void(32), a raw bit string, which is then passed to the string_to_hex function. Entering the following at the command line:
- string_suffix : Returns a substring of a specified length that ends at the end of the parent string.
Syntax : string string_suffix(string str, integer length)
e.g., string_suffix(str = "25 February 2018", length = 4)
Output : "2018"
e.g., string_suffix("25 February 2018", 18)
Output : "25 February 2018"
e.g., string_suffix("25 February 2008", -4)
Output : ""
Date Functions :
- date_add_months : This function returns the internal representation of a date resulting from adding or subtracting a number of months to or from the specified date.
e.g., let date("YYYYMMDD") mydate = "20200229";
date_add_months(in_date = mydate, months = 12);
44253
e.g., (date("YYYY-MM-DD"))date_add_months(mydate, 12);
--> "2021-02-28"
- date_day : This function returns the day of the month of a date
syntax : long date_day(date or datetime in_date)
e.g., date_day((date("YYYY-MM-DD"))"2024-07-31")
--> 31
- date_day_of_month : This function returns the day in the month of a specified date.
Syntax : long date_day_of_month(date or datetime in_date)
e.g., date_day_of_month((date("YYYY-MM-DD"))"2024-06-21")
--> 21
- date_day_of_week : This function returns the numeric day of the week of a specified date.
Syntax : long date_day_of_week(date or datetime in_date)
e.g., date_day_of_week((date("YYYYMMDD"))"20210514")
--> 6
- date_day_of_year : This function returns the numeric day in the year of a specified date.
Syntax : long date_day_of_year(date or datetime in_date)
e.g., date_day_of_year((date("YYYYMMDD"))"20190518")
--> 138
e.g., date_day_of_year((date("YYYYMMDD"))"20200518")
--> 138
- date_difference_days: This function returns the number of days between two specified dates
Syntax: double date_difference_days(date or datetime date1, date or datetime date2)
e.g., let date("YYYY/MM/DD") mydate = "2021/02/28";
date_difference_days(date1 = mydate, date2 = (datetime("YYYY/MM/DD"))"2021/02/26");
--> 2.0
- date_difference_months : This function returns the number of months between two specified dates.
Syntax : double date_difference_months(date or datetime date1, date or datetime date2)
e.g., let date("YYYYMMDD") mydate = "20210228";
date_difference_months(date1 = (date("YYYYMMDD")) "20210328", date2 = mydate);
--> 1.0
- date_ month : This function returns the numeric month of the year in a specified date.
Syntax : long date_month(date or datetime in_date)
e.g., date_month((date("YYYYMMDD"))"20210518");
--> 5
- date_month_end : This function returns the last day of a specified month.
Syntax : long date_moth_end(integer month [ integer year ] )
e.g., date_month_end(month = 11) --> 30
e.g., date_month_end(12) --> 31
e.g. date_month_end(2, 1990) --> 28
e.g., date_month_end(2, 1996) --> 29
- date_to_int : This function returns the number of days from a specified date relative to January 1, 1900.
Syntax : long date_to_int(date or datetime in_date)
e.g., date_to_int(now()) --> 43802
- date_week_of_year : This function returns the numeric week of the year for a specified date as an object of type
Syntax : long date_week_of_year(date or datetime in_date)
e.g., date_week_of_year((date("YYYY-MM-DD"))"2019-01-01") --> 1
e.g., date_week_of_year((date("YYYY-MM-DD"))"2018-12-31") --> 1
e.g., date_week_of_year((date("YYYY-MM-DD"))"2018-12-30") --> 52
- date_year : This function returns the year of a specified date
Syntax : long date_year(date or datetime in_date)
e.g., date_year((date("YYYYMMDD"))"20210518") --> 2021
- datetime_add : This function returns the result of adding a specified number of days, hours, minutes, seconds and microseconds to the value of a date.
Syntax : datetime or long datetime_add(date or datetime or long in_datetime, integer(8) days=0, integer(8) hours=0, integer(8) minutes=0, interger(8) seconds=0, integer(8) microseconds=0)
e.g., datetime_add(in_datetime = (date("YYYYMMDD")) "20161029", days = 2 hours = 3, minutes = 4, seconds = 5, microseconds = 6)
--> "20161031030405000006+0000"
- datetime_add_months : This function returns the result of adding or subtracting a specified number of months to or from the value of a datetime.
Syntax : datetime or long datetime_add_months(date or datetime or long in_datetime, integer months)
e.g., let datetime ("YYYYMMDD") mydate = "20210101";
datetime_add_months(in_datetime = mydate, months = 3);
--> "20210401000000000000+0000"
(date("YYYY-MM-DD")) datetime_add_months(mydate, 3)
--> "2021-04-01"
e.g., datetime_add_months((datetime("YYYYMMDD")) "20170131", -1)
--> "20161231000000000000+0000"
e.g., datetime_add_months((datetime("YYYYMMDD")) "20200131", 1)
-> "20200229000000000000+0000"
- datetime_change_zone : This function returns the time in a specified time zone that is synonymous with an input time.
Syntax : datetime datetime_change_zone(date or datetime in_datetime, number new_zone_offset)
e.g., datetime_change_zone(in_datetime = (datetime("YYYYMMDD")) "20151029", new_zone_offset = -240)
--> "20151028200000000000-0400"
- datetime_day : This function returns the number of the day of the month in a specified date.
Syntax : long datetime_day(date or datetime or long in_datetime)
e.g., m_eval 'datetime_day((datetime("YYYY-MM-DD HH24:MI:SS"))"2024-12-05 05:00:00")' --> 5
- datetime_day_of_month : This function returns the number of the day of the month in a specified date
Syntax : long datetime_day_of_month(date or datetime or long in_datetime)
e.g., datetime_day_of_month((datetime("MMDDYYYY")) "10292021"); --> 29
- datetime_day_of_week : This function returns the day of the week of a specified date.
Syntax : long datetime_day_of_week(date or datetime or long in_datetime)
e.g., datetime_day_of_week(((datetime("MMDDYYYY")) "10292016")) --> 7
- datetime_day_of_year : This function returns the day of the year in a specified date.
Syntax : long datetime_day_of_year(date or datetime or long in_datetime)
e.g., datetime_day_of_year(((datetime("MMDDYYYY")) "10292020")) --> 303
- datetime_difference : This function returns a record representing the difference between two specified dates.
Syntax : datetime_difference_type datetime_difference(date or datetime or long datetime1, date or datetime or long datetime2)
e.g.,
- datetime_difference_abs: This function returns a record representing the absolute value of the difference between two specified dates.
Syntax : datetime_difference_type datetime_difference_abs(date or datetime or long datetime1, date or datetime or long datetime2)
e.g., datetime_difference_abs(datetime1 = (datetime("MMDDYYYY")) "10292015", datetime2 = (datetime("MMDDYYYY")) "12252015")
[record
days 57
hours 0
minutes 0
seconds 0
microseconds 0]
- datetime_difference_days : This function returns the number of days between two specified dates
Syntax : double or long datetime_difference_days(date or datetime or long datetime1, date or datetime or long datetime2)
e.g., let datetime("YYYY/MM/DD") mydate = "2021/02/28";
datetime_difference_days(datetime1 = mydate, datetime2 = (datetime("YYYY/MM/DD")) "2021/02/26") --> 2.0
e.g., datetime_difference_days(mydate, (datetime("YYYY/MM/DD HH24:MI")) "2021/02/28 12:00") --> -.5
- datetime_difference_hours : This function returns the number of hours between two specified dates
Syntax : double or long datetime_difference_hours(date or datetime or long datetime1, date or datetime or long datetime2)
e.g., let datetime("YYYY/MM/DD") mydate = "2021/02/28";
datetime_difference_hours(datetime1 = mydate, datetime2 = (datetime("YYYY/MM/DD")) "2021/02/26")
--> 48.0
- datetime_difference_minutes : This function returns the number of minutes between two specified dates.
Syntax : double or long datetime_difference_minutes(date or datetime or long datetime1, date or datetime or long datetime2)
e.g., let datetime("YYYY/MM/DD") mydate = "2015/02/28";
datetime_difference_minutes(datetime1 = mydate, datetime2 = (datetime("YYYY/MM/DD")) "2015/02/26")
--> 2880.0
- datetime_difference_months : This function returns the number of months between two specified dates
Syntax : double or long datetime_difference_months(date or datetime or long datetime1, date or datetime or long datetime2)
e.g., let date("YYYY/MM/DD") mydate = "2018/03/31";
datetime_difference_months(datetime1 = mydate, datetime2 = (datetime("YYYY/MM/DD"))"2020/02/29")
--> -23.0
- datetime_difference_seconds : This function returns the number of seconds between two specified dates
Syntax : double or long datetime_difference_seconds(date or datetime or long datetime1, date or datetime or long datetime2)
e.g., let datetime("YYYY/MM/DD HH:MI:SS") mydate = "2021/02/28 10:33:33";
datetime_difference_seconds(datetime1 = mydate, datetime2 = (datetime("YYYY/MM/DD HH:MI:SS")) "2021/02/27 10:33:33");
--> 86400.0
- datetime_from_unixtime : This function returns a datetime value that corresponds to the number of seconds elapsed since January 1, 1970(Unix time)
Syntax : datetime datetime_from_unixtime(integer(8) unixtime)
e.g., datetime_from_unixtime((integer(8))1234567890)
--> "20090213233130000000"
(datetime("YYYY-MM-DD HH24:MI:SS"))datetime_from_unixtime(((integer(8))1234567890))
--> "2009-02-13 23:31:30"
- datetime_hour : This function returns the hour of a specified date
Syntax : long datetime_hour(date or datetime or long in_datetime)
e.g., datetime_hour(now()) --> 13
- datetime_minute : This function returns the minutes of a specified date
Syntax : long datetime_minute(date or datetime or long in_datetime)
e.g., datetime_minute(now()) --> 43
- datetime_second : This function returns the seconds of a specified date
Syntax : long datetime_second(date or datetime or long in_datetime)
e.g., datetime_second(now()) --> 18
******************************Keep Learning******************************Stay Focused ******************************
Comments
Post a Comment