TapHome

Text, String and Byte array

TapHome script string and collection functions — LENGTH, BYTECOLLECTION, INDEXOF, COPY, REPLACE, SPLIT, COMPARE, APPEND, INSERT, REMOVEAT, GETAT, SETAT, ENCODE, DECODE, EQUALS.

LENGTH

Returns length of an object or number of bytes. Object can be a number, boolean, string or Collection.

LENGTH( object )

Examples:

LENGTH(“Hello World”)			(Result is 11)
LENGTH(“40”)				(Result is 2)
LENGTH(40)					(Result is 8)
LENGTH(BYTECOLLECTION(“010203”)	(Result is 3)

BYTECOLLECTION

Creates a Collection from specified hexadecimal values

BYTECOLLECTION( bytes )

Examples:

BYTECOLLECTION(“010203”) 				(Result is Collection<UInt8> {01, 02, 03})
BYTECOLLECTION(“aa, be1-1,fe”) 			(Result is Collection<UInt8> {aa be 11 fe})

INDEXOF

Returns index of specified element in string or collection. Returns -1 if element cannot be found.

INDEXOF( string/collection, element )

Examples:

INDEXOF("Hello", “H”)					(Result is 0)
INDEXOF("Hello World", “Wor”)				(Result is 6)
INDEXOF("Hello World", “Wor”)				(Result is 6)
INDEXOF("Hello World", “or12”)				(Result is -1)
INDEXOF(BYTECOLLECTION("ab cd ee ff 01 02"), 2)	(Result is 5)
INDEXOF({1, 2, 3}, 3)						(Result is 2)

COPY

Copies specified string or collection (or part of them)

COPY( string/collection, startIndex, length)

Examples:

COPY("Hello")					(Result is “Hello”)
COPY("Hello World", 2)				(Result is “llo World”)
COPY("Hello World", 2, 4)				(Result is “llo ”)
COPY(BYTEARRAY("01020304")			(Result is byte array 01020304)
COPY(BYTEARRAY("01020304", 2, 1)		(Result is byte array 03)

REPLACE

Returns a new string or collection, in which all occurrences of specified value are replaced with new value.

REPLACE( string/collection, oldValue, newValue)

Examples:

REPLACE("Hello", “l”, “”)				(Result is “Heo”)
REPLACE("Hello", “lo”, “22”)			(Result is “Hel22”)
REPLACE(BYTECOLLECTION(“050607"), 5, 9)	(Result is Collection<UInt8>{09, 06, 07}

SPLIT

Splits string to substrings based on separator parameters.

SPLIT( string, string )
SPLIT( string, char )
SPLIT( string, Collection<string> )
SPLIT( string, Collection<char> )

Examples:

SPLIT("1;2;3;4", “;”)			(Result is Collection<String>{“1”, “2”, “3”, “4”})
SPLIT("1;2;3.4", “2;”)		(Result is Collection<String>{“1;”, “3.4”})
SPLIT("1;2;3.4", {“2”, “3.”)		(Result is Collection<String>{“1;”, “;”, “4”})

COMPARE

Compare 2 strings and returns an integer that indicates their relative position in the sort order.

COMPARE( string, string, CompareOptions )

Examples:

COMPARE("abc", “abc”)						(Result is 0)
COMPARE("abc", “ABC”)						(Result is 32)
COMPARE("abc", “ABC”, CompareOptions.IgnoreCase)	(Result is 0)

APPEND

Append value to collection or string and returns new object with appended value.

APPEND( string, string )
APPEND( Collection, value )

Examples:

APPEND({1, 2}, 3)     (Result is Collection<Double>{1, 2, 3})
APPEND("abc", “def”)  (Result is “abcdef”)

INSERT

Insert value to collection or string. Returns collection or string with inserted value.

INSERT( collection, index, value )
INSERT( string, index, value )

Examples:

INSERT(“Hello”, 5, “ World”)      (Result is “Hello World”)
INSERT(“Hello”, 1, “i”)			  (Result is “Hiello”)
INSERT({1, 2, 4}, 2, 3)			  (Result is Collection<Double>{1, 2, 3, 4})

REMOVEAT

Remove elements from collection or string based on element index and length. Returns collection or string without specified elements.

REMOVEAT( collection, index, length )
REMOVEAT( string, index, length )

Examples:

REMOVEAT(“Hello”, 1)			(Result is “Hllo”)
REMOVEAT(“Hello”, 3, 2)			(Result is “Ho”)
REMOVEAT({1, 2, 3, 4}, 2)			(Result is Collection<Double>{1, 2, 4})
REMOVEAT({1, 2, 3, 4}, 2, 2)		(Result is Collection<Double>{1, 2})

GETAT

Get element value from collection or string based on provided index.

GETAT( collection, index )
GETAT( string, index )

Examples:

GETAT(“Hello”, 2)			(Result is “l”)
GETAT({1, 2, 4}, 2)			(Result is 4)

SETAT

Set element value in collection or string at provided index.

SETAT( collection, index, value )
SETAT( string, index, value )

Examples:

SETAT(“Hello”, 1, “a”)          (Result is “Hallo”)
SETAT(“Hello”, 4, “o World”)    (Result is “Hello World”)
SETAT({1, 2, 4}, 2, 3)          (Result is Collection<Double>{1, 2, 3})

ENCODE

Encodes specified string using on of the formats and returns the new string.

ENCODE( string, format )

Supported formats:

  • XML
  • Base64

Examples:

ENCODE("Hello", “xml”)				(Result is “Hello”)
ENCODE("<Hello id=1>", “xml”)		(Result is “&lt;Hello id=1&gt;”)
ENCODE("Hello", “base64”)			(Result is “SGVsbG8=”)

DECODE

Decodes specified string using one of the formats and returns the new string.

DECODE( string, format )

Supported formats:

  • XML
  • Base64

Examples:

DECODE("Hello", “xml”)				  (Result is “Hello”)
DECODE("&lt;Hello id=1&gt;", “xml”)   (Result is “<Hello id=1>”)
DECODE("SGVsbG8=", “base64”)		  (Result is “Hello”)

EQUALS

Compares two numbers with floating point. The numbers are considered to be equal if | n1 - n2 |< epsilon The default value of threshold (*epsilon) *is 0.005 and it is an optional parameter.

EQUALS( number1, number2, epsilon=0.005 )

Examples:

EQUALS(1.33, 1.33)          1.0 (true)
EQUALS(1.333, 1.3335)		1.0 (true)
EQUALS(1.333, 1.338)		1.0 (false)
EQUALS(1.333, 1.338, 0.01)	1.0 (true)
EQUALS(NAN, NAN)		    1.0 (true)