-
Notifications
You must be signed in to change notification settings - Fork 0
Computing Functions Strings
CharAt | Return one character from position. The first position has index 0 |
EndsWith | Tests if string ends with the specified suffix. |
ExtractDigits | Retrieves all digits from a string |
Format | Formats a number into a string by mask |
IndexOf | Returns the index within string of the first occurrence of the specified substring. |
IsBlank | Checks if string contain only whitespace characters or null |
IsEmpty | Checks that the string contains no characters or null. |
Like | Returns true if the condition specified in the template is met, similar to the 'like' operation as in databases |
LikeRegexp | Return true if the condition specified by the regular expression is true |
LTrim | Remove leading whitespace |
NormalizeSpaces | Returned string with normalized spaces |
PadLeft | Adds characters to the left of the string until the string reaches the specified length. |
PadRight | Adds characters to the right of the string until the string reaches the specified length. |
RemoveSpaces | Remove all space characters |
RemoveWhitespaces | Remove all whitespaces characters |
Replace | Returns a string resulting from replacing all occurrences of oldString in this string with newString. |
RTrim | Remove trailing whitespace |
StartsWith | Tests if string starts with the specified prefix. |
Substring | Returns a string that is a substring of this string. |
ToString | Convert any value to String |
Trim | Returns a string whose value is this string, without leading and trailing whitespace characters |
TrimToNull | Returns a string without leading and trailing whitespace characters or null if string is empty |
Return one character from position. The first position has index 0.
charAt(string, position)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | The incoming string from which to extract the character at the given position. | |
position | int | Yes | The position at which the desired character is located. |
Type: java.lang.String
The string with the desired character.
Formula formula = new Formula("charAt('abcdf', 2)");
String str = engine.calc(formula, String.class);
assertEquals("c", str);
Tests if string ends with the specified suffix.
endsWith(string, suffix)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string to test | |
suffix | String | Yes | suffix |
Type: boolean
If the string ends with a suffix, then true, otherwise false.
Formula formula = new Formula("endsWith('abcdf', 'df')");
boolean isEndsWith = engine.calc(formula, Boolean.class);
assertTrue(isEndsWith);
Retrieves all digits from a string.
The function does not extract the sign of a number.
extractDigits(string)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
Type: java.lang.String
All digits contained in the string.
Formula formula = new Formula("extractDigits('1a2b3c-45(6)d')");
String result = engine.calc(formula, String.class);
assertEquals("123456", result);
Formats a number into a string by mask.
Example:
number: 12345678901
mask: S(XXX)XXX-XXX XX
result: +(123)456-789 01
format(value, mask, digitHolder, signHolder)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
value | String | Yes | Incoming value to format | |
mask | String | Yes | Mask to format | |
digitHolder | String | No | Sign holder | 'S' |
signHolder | String | No | Digit holder | 'X' |
Type: java.lang.String
Formatted string.
Formula formula = new Formula("format('12345678901', 'S(XXX)XXX-XXX XX')");
String result = engine.calc(formula, String.class);
assertEquals("+(123)456-789 01", result);
Returns the index within string of the first occurrence of the specified substring.
indexOf(string, substring)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | |
substring | String | Yes | A substring to search for in an incoming string |
Type: int
Position in the incoming string, or 0 if the substring was not found.
Formula formula = new Formula("indexOf('abcdf', 'aaa')");
int pos = engine.calc(formula, Integer.class);
assertEquals(-1, pos);
formula = new Formula("indexOf('abcdf', 'ab')");
pos = engine.calc(formula, Integer.class);
assertEquals(0, pos);
formula = new Formula("indexOf('abcdf', 'bc')");
pos = engine.calc(formula, Integer.class);
assertEquals(1, pos);
Checks if string contain only whitespace characters or null.
isBlank(string)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
Type: boolean
true when string null or empty or contain white space characters.
Formula formula = new Formula("isBlank('abcdf')");
boolean isBlank = engine.calc(formula, Boolean.class);
assertFalse(isBlank);
formula = new Formula("isBlank(null)");
isBlank = engine.calc(formula, Boolean.class);
assertTrue(isBlank);
formula = new Formula("isBlank(' \t\n ')");
isBlank = engine.calc(formula, Boolean.class);
assertTrue(isBlank);
Checks that the string contains no characters or null.
isEmpty(string)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
Type: boolean
true when the string contains no characters or null.
Formula formula = new Formula("isEmpty('abcdf')");
boolean isBlank = engine.calc(formula, Boolean.class);
assertFalse(isBlank);
formula = new Formula("isEmpty(' ')");
isBlank = engine.calc(formula, Boolean.class);
assertFalse(isBlank);
formula = new Formula("isEmpty('')");
isBlank = engine.calc(formula, Boolean.class);
assertTrue(isBlank);
formula = new Formula("isEmpty(null)");
isBlank = engine.calc(formula, Boolean.class);
assertTrue(isBlank);
Returns true if the condition specified in the template is met, similar to the 'like' operation as in databases.
like(string, template)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | The incoming string to test. | |
template | String | Yes | expression, where character '_' substitute any one characters character '%' substitute more than one of any characters. |
Type: boolean
True if the tested string matches the search expression.
assertTrue(engine.calc(new Formula("like('abcdfab', 'a%b')"), Boolean.class));
assertTrue(engine.calc(new Formula("like('abcdfabghc', 'a%b%c')"), Boolean.class));
Return true if the condition specified by the regular expression is true
likeRegexp(string, template)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | The incoming string to test | |
template | String | Yes | regexp expression |
Type: boolean
True if the tested string matches the search regexp expression.
assertTrue(engine.calc(new Formula("likeRegexp('abcdfab', '^a.*b$')"), Boolean.class));
assertTrue(engine.calc(new Formula("likeRegexp('abcdfabghc', '^a.*b.*c$')"), Boolean.class));
Remove leading whitespace
ltrim(string)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
Type: String
String without leading whitespace.
Formula formula = new Formula("lTrim(' abcdef')");
String result = engine.calc(formula, String.class);
assertEquals("abcdef", result);
formula = new Formula("lTrim('abcdef')");
result = engine.calc(formula, String.class);
assertEquals("abcdef", result);
formula = new Formula("lTrim(null)");
result = engine.calc(formula, String.class);
assertNull(result);
formula = new Formula("lTrim(' \t\n ')");
result = engine.calc(formula, String.class);
assertEquals("", result);
Returned string with normalized spaces
normalizeSpaces(string)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
Type: String
String with normalized spaces.
Formula formula = new Formula("normalizeSpaces('a b cd f')");
String result = engine.calc(formula, String.class);
assertEquals("a b cd f", result);
formula = new Formula("normalizeSpaces(' a b c d\nf ')");
result = engine.calc(formula, String.class);
assertEquals(" a b c d\nf ", result);
Adds characters to the left of the string until the string reaches the specified length.
padLeft(string, quantity, sample)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
quantity | int | Yes | Total length of the string after adding characters | null |
sample | String | Yes | Added symbols | null |
Type: String
String with added characters.
Formula formula = new Formula("padLeft('AAA', 10, 'B')");
String result = engine.calc(formula, String.class);
assertEquals("BBBBBBBAAA", result);
formula = new Formula("padLeft('AAA', 2, 'B')");
result = engine.calc(formula, String.class);
assertEquals("AAA", result);
Adds characters to the right of the string until the string reaches the specified length.
padRight(string, quantity, sample)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
quantity | int | Yes | Total length of the string after adding characters | null |
sample | String | Yes | Added symbols | null |
Type: String
String with added characters.
Formula formula = new Formula("padRight('AAA', 10, 'B')");
String result = engine.calc(formula, String.class);
assertEquals("AAABBBBBBB", result);
formula = new Formula("padRight('AAA', 2, 'B')");
result = engine.calc(formula, String.class);
assertEquals("AAA", result);
Remove all space characters
removeSpaces(string)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
Type: String
String without space characters
formula = new Formula("removeSpaces(' a b c d f ')");
result = engine.calc(formula, String.class);
assertEquals("abcdf", result);
Remove all whitespaces characters
removeWhitespaces(string)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
Type: String
String without whitespaces characters
formula = new Formula("removeWhitespaces(' a b\nc\td f ')");
result = engine.calc(formula, String.class);
assertEquals("abcdf", result);
Returns a string resulting from replacing all occurrences of oldString in this string with newString.
padRight(string, oldString, newString)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
oldString | String | Yes | The old string | null |
newString | String | Yes | The new string | null |
Type: String
String with replaced characters.
Formula formula = new Formula("replace('abcdefbcgh', 'bc', 'BC')");
String res = engine.calc(formula, String.class);
assertEquals("aBCdefBCgh", res);
Remove trailing whitespace
rtrim(string)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
Type: String
String without trailing whitespace.
Formula formula = new Formula("rTrim('abcdef ')");
String result = engine.calc(formula, String.class);
assertEquals("abcdef", result);
Tests if string starts with the specified prefix.
startsWith(string, prefix)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string to test | |
prefix | String | Yes | Prefix |
Type: boolean
If the string starts with a prefix, then true, otherwise false.
Formula formula = new Formula("startsWith('abcdf', 'ab')");
boolean isEndWith = engine.calc(formula, Boolean.class);
assertTrue(isEndWith);
formula = new Formula("startsWith('abcdf', 'df')");
isEndWith = engine.calc(formula, Boolean.class);
assertFalse(isEndWith);
Returns a string that is a substring of this string.
Without any exception when the index goes out of bound.
The start and length can be less than zero. In this case, the calculation is carried out from the end.
substring(string, start, length)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | The incoming string | |
start | int | Yes | The start position | |
length | int | Yes | Length of substring |
Type: java.lang.String
A substring from the incoming string.
Formula formula = new Formula("substring('abcdefgh', 0, 2)");
String res = engine.calc(formula, String.class);
assertEquals("ab", res);
formula = new Formula("substring('abcdefgh', 2, 5)");
res = engine.calc(formula, String.class);
assertEquals("cdefg", res);
formula = new Formula("substring('abcdefgh', 2, 50)");
res = engine.calc(formula, String.class);
assertEquals("cdefgh", res);
formula = new Formula("substring('abcdefgh', 20, 50)");
res = engine.calc(formula, String.class);
assertEquals("", res);
formula = new Formula("substring('abcdefgh', -5, 2)");
res = engine.calc(formula, String.class);
assertEquals("de", res);
formula = new Formula("substring('abcdefgh', -5, -2)");
res = engine.calc(formula, String.class);
assertEquals("bc", res);
formula = new Formula("substring('abcdefgh', -50, 2)");
res = engine.calc(formula, String.class);
assertEquals("", res);
formula = new Formula("substring('abcdefgh', -5, 20)");
res = engine.calc(formula, String.class);
assertEquals("defgh", res);
formula = new Formula("substring('abcdefgh', 5, -20)");
res = engine.calc(formula, String.class);
assertEquals("abcde", res);
Convert any value to String
toString(string)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
Type: String
The value as string.
Returns a string whose value is this string, without leading and trailing whitespace characters
trim(string)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
Type: String
String without leading and trailing whitespace characters.
Formula formula = new Formula("trim(' abcdef ')");
String result = engine.calc(formula, String.class);
assertEquals("abcdef", result);
Returns a string without leading and trailing whitespace characters or null if string is empty
trimToNull(string)
Parameter Name | Type | Require | Description | Default Value |
---|---|---|---|---|
string | String | Yes | Incoming string | null |
Type: String
String without leading and trailing whitespace characters or null if string is empty.
Formula formula = new Formula("trimToNull(' abcdef ')");
String result = engine.calc(formula, String.class);
assertEquals("abcdef", result);
formula = new Formula("trimToNull(null)");
result = engine.calc(formula, String.class);
assertNull(result);
formula = new Formula("trimToNull(' \t\n ')");
result = engine.calc(formula, String.class);
assertEquals(null, result);
formula = new Formula("trimToNull(' ')");
result = engine.calc(formula, String.class);
assertEquals(null, result);
- Home
- Extendable Query Language
- Computing
- Simple Usage
- Own Value Extraction
- Functions
- What is Type
- Known Types
- Add Own Type
- Data conversion
- Generate SQL Query
- Find files