DLV EXTERNAL BUILTINS - String_lib Library

 

This library includes the definition of 10 external built-in predicates for the manipulation of text strings.

 


BUILT-IN PREDICATE

DESCRIPTION

#like(string, model)

Match string with model.

#likeCS(string, model)

Match string with model in a case sensitive way.

#toLower(string, result)

Convert uppercase letters to the corresponding lowercase ones.

#toUpper(string, result)

Convert lowercase letters to the corresponding uppercase letters.

#isLower(string)

Return true if string includes only lowercase letters.

#isUpper(string)

Return true if string includes only uppercase letters.

#trim(string, result)

Delete all space characters from string.

#substr(string, substring)

Return true if substring is a part of string.

#strlen(string, result)

Compute the length of string.

#strcat(string1, string2, result)

Compute the concatenation of  string1 with string2.

 

 

 

 

#like

Matches a string with a string model. A string model is a string defining the format of a desired string. It may specify some characters that must be included in the string to match, but also intervals of characters and “jolly” characters.

The following table shows all kinds of expressions, including jolly characters, that can be used in a model.

character/expression in the model

matching result

?

(question mark) Any single character

_

(underscore) Any single character

*

Zero or more of any character

%

Zero or more of any character

#

Any single digit

[character_list]

Any single character included in character_list

[!character_list]

Any single character not included in character_list

[character_intervals]

Any single character included in the character_intervals

[!character_intervals]

Any single character not included in the character_intervals

All the special characters (? _ * % # [ ! ]) can not be used ‘directly’ in the model string, but must be enclosed in square brackets.

The following table shows some examples of string models and corresponding matching and non-matching strings.

Model

Matching strings

Non matching strings

“a*a”

“aa”, “aBa”, “albA”, “aLBa”

“aDFRE”, “da”

“*ab

“Abher”, “asaBDfr”, “Xab”

“Adfb”, “bac”

“*Roma###”

“Via roma, 123”

“Via roma, 123A”

“a?a”

“asa”, “a7a”, “aFa”

“aFFFa”

“a#a”

“a7a”, “a4a”

“ata”, “a34a”

“[abcd

“a”, “b”, “c”, “d”

“f”, “y”, “

“[a-z]”

“f”, “p”, “j”

“, “&”

“[!a-z]”

“, “&”, “%”

“b”, “c”

“[a-z0-9]

“b”, “

“$”, “&”

“*[#]”

“m3#”, “john#”

“aaa”, “34#d”

 

Syntax

#like(string, model)

string is the text string to match with the model

model is the string model against with the string will be matched

Available Patterns

ii (string, model) :                                 Returns true if string matches with model

Notes

Returns false if one of the arguments is not a string.

See also

#likeCS

 

#likeCS

Behaves exactly as the like built-in (see above) but it’s case sensitive. So, if the model includes for instance the character ‘A’, only an uppercase ‘A’ in the string will match the model.

Syntax

#likeCS(string, model)

string is the text string to match with the model (case sensitively)

model is the string model against with the string will be matched (case sensitively)

Available Patterns

ii (string, model) :                                 Returns true if string matches with model (case sensitively)

Notes

Returns false if one of the arguments is not a string.

See also

#like

 

 


#toLower

Converts uppercase letters to the corresponding lowercase ones.

Syntax

#toLower(string, result)

string is the text string to be converted

result is the resulting string with all uppercase letters converted in the corresponding lowercase ones

Available Patterns

ii (string, result) :                                  Returns true if result is the lowercase equivalent of string

io (string, Result) :                                Set result to the lowercase equivalent of string

Notes

Returns false if one of the arguments is not a string.

See also

#toUpper, #isLower, #isUpper

 

 


#toUpper

Converts lowercase letters to the corresponding uppercase ones.

Syntax

#toUpper(string, result)

string is the text string to be converted

result is the resulting string with all lowercase letters converted in the corresponding uppercase ones

Available Patterns

ii (string, result) :                                  Returns true if result is the uppercase equivalent of string

io (string, Result) :                                Set result to the uppercase equivalent of string

Notes

Returns false if one of the arguments is not a string.

See also

#toLower, #isLower, #isUpper

 

 


#isLower

Returns true if a string includes only lowercase letters.

Syntax

#isLower(string)

string is the text string to be checked

Available Patterns

i (string) :                                              Returns true if string includes only lowercase letters

Notes

Returns false if one of the arguments is not a string.

See also

#toUpper, #toLower, #isUpper

 

 


#isUpper

Returns true if a string includes only lowercase letters.

Syntax

#isUpper(string)

string is the text string to be checked

Available Patterns

i (string) :                                              Returns true if string includes only uppercase letters

Notes

Returns false if one of the arguments is not a string.

See also

#toUpper, #toLower, #isLower

 

 


#trim

Deletes all spaces from a string.

Syntax

#trim(string, result)

string is the text string to be trimmed

result is the text string trimmed

Available Patterns

ii (string, result) :                                  Returns true if result is the trimmed equivalent of string

io (string, Result) :                                Set Result to the trimmed equivalent of string

Notes

Returns false if one of the arguments is not a string.

See also

#substr, #strlen, #strcat

 

 


#substr

Returns true if the string passed as second argument is a substring of the string passed as first argument.

Syntax

#substr(string, sub_string)

string is the text string that could possibly include substring

substring is the text string that could be possibly included into string

Available Patterns

ii (string, substring) :                             Returns true if substring is part of string

Notes

Returns false if one of the arguments is not a string.

See also

#trim, #strlen, #strcat

 

 


#strlen

Computes the length of a string.

Syntax

#strlen(string, result)

string is the text string we want to compute the length

result is the number of characters included into string

Available Patterns

ii (string, result) :                                  Returns true if result is equal to the length of string

io (string, Result) :                                Set Result to the length of string

Notes

Returns false if either string is not a string or result is not an integer number.

See also

#substr, #trim, #strcat

 

 


#strcat

Computes the concatenation of two strings.

Syntax

#strcat(string1, string2, result)

string1 is the first text string to concatenate

string2 is the second text string to concatenate

result is the text string obtained appending string2 to string1

Available Patterns

iii (string1, string2, result) :                   Returns true if result is the concatenation of string1 and string2

iio (string1, string2, Result) :                Set Result to the concatenation of string1 and string2

ioi (string1, String2, result) :                 Set String2 so that result is the concatenation of string1 and String2

oii (String1, string2, result) :                 Set String1 so that result is the concatenation of String1 and string2

Notes

Returns false if one of the arguments is not a string.

See also

#trim, #substr, #strlen