String Functions - Gnorion/BizVR GitHub Wiki
| Function | Example |
|---|---|
| INFIX | |
| += |
'ABC'+='XYZ' returns 'ABCXYZ' |
| + |
'THE' + ' ' + 'CAT' returns 'THE CAT' concatenate three strings |
| . |
'THE ' + $n + ' CATS' returns 'THE 2 CATS' if n is 2. Type conversion is automatic |
| < |
'CAR' < 'CAT' returns true compare two strings |
| <= |
'CAT' <= 'CAT' returns true compare two strings |
| <> |
'DOG' <> 'CAT' returns true compare two strings |
| '>' |
'CAT' > 'CAR' returns true compare two strings |
| '>=' |
'CAT' >= 'CAR' returns true compare two strings |
| FUNCTIONS | |
| alphabet(string) |
alphabet('THE CAT SAT ON THE MAT') returns ' ACEHMNOST' |
| characterAt(string,i) |
characterAt('THE CAT SAT ON THE MAT',6) returns A. Null if i not in 1..string length |
| charsIn(string,validset) |
charsIn('THE CAT SAT ON THE MAT',' ACEHMNOST') returns true if every char in the string is in the validset |
| concat(string,string)) |
concat('THE CAT SAT',' ON THE MAT') returns 'THE CAT SAT ON THE MAT' (see also +) |
| contains(string,substring) |
contains('THE CAT SAT ON THE MAT','THE') returns 2. The number of occurrences |
| . |
contains('THe CAT SAT ON THE MAT','THE')returns 1 |
| . |
contains(toUpper('THE CaT SAT oN THE MaT'),toUpper('Mat')) returns 1 |
| containsBlanks(string) |
containsBlanks(' THE CAT SAT ON THE MAT ') returns 7 |
| containsSpecialChars(string) |
containsSpecialChars*' THE CAT SAT ON THE !@%% MAT ') returns 4 |
| endsWith(string,string) |
endsWith(' THE CAT SAT ON THE MAT','AT') returns true |
| equals(string,string) |
equals('THE CAT SAT ON THE MAT','THe CAT SAT ON THE MAT')returns false |
| equalsIgnoreCase(string,string) |
equalsIgnoreCase('THE CAT SAT ON THE MAT','THe CAT SAT ON THE MAT') returns true |
| indexOf(string,substring) |
indexOf('THE CAT SAT ON THE MAT','THE') returns 1 |
| isInteger(string) |
isInteger('42') returns true |
| isDecimal(string) |
isDecimal('3.14') returns true |
| isDateTime(string) |
isDateTime('12/1/2017 12:00:00 AM') returns true |
| distance(string,string) |
distance(('https://www.wellsfargo.com/','https://www.wellsforgo.com/') returns 1. Number of edits to convert. Used in fraud detection. Uses Levenstein |
| toProtein(string) |
toProtein('GUUCACUUAACACCCGAGAAAUGA') returns Val-His-Leu-Thr-Pro-Glu-Lys-. the protein(s) coded by a string containing only A,C,U,G |
| regexMatches(string,regex) | returns true if the string matches the regular expression |
| regexReplace(string,regex,string) | anything that matches regex is replaced with string. |
| replace(fromStr,toStr) |
replace('THE CAT SAT ON THE MAT','THE','A') returns 'A CAT SAT ON A MAT' |
| replace(fromStr,toStr,startAt) |
replace('THE CAT SAT ON THE MAT','THE','A',1) returns 'THE CAT SAT ON A MAT' |
| size(string) |
size('THE CAT SAT ON THE MAT') returns 22 |
| soundex(string) |
soundex('Robert')=soundex('Rupert') returns true. Numeric value representing the phonetic sound of the string. 'R163' in this example |
| metaphone(string) |
metaphone('mississipi')=metaphone('mosasupy') returns true since both produce 'MSSP'. |
| startsWith(string,string) |
startsWith('THE CAT SAT ON THE MAT','THE C') returns true |
| toDateTime(string) |
toDateTime('12/1/2017 12:00:00 AM') returns null if the string cannot be converted; otherwise returns the datetime |
| toDecimal(string) |
toDecimal('3.1415') returns 3.1415. returns null if the string cannot be converted; otherwise returns the decimal value |
| toInteger(string) |
toInteger('42') returns 42. returns null if the string cannot be converted; otherwise returns the integer value |
| toLower(string) |
toLower('THE CAT SAT ON THE MAT') returns 'the cat sat on the mat' |
| toUpper(string) |
toUpper('the cat sat on the mat') returns 'THE CAT SAT ON THE MAT' |
| trimSpaces(string) |
trimSpaces(' THE CAT SAT ON THE MAT ') returns 'THE CAT SAT ON THE MAT' |
Note: Any string literal in the examples may be replaced with any expression that evaluates to a string. Even a complex one involving collections.
For example person.gender[age>65]->sortedBy(age)->first.equalsIgnoreCase('male') as long as the final result is a string