This string predicate replaces each single quote character in the term argument with two single quote characters. This predicate can only be used inside a string expression of is_string/2. This predicate is useful for importing non-prolog data which may contain single quotes and also for ensuring that data written to a database is correct. SQL uses single quote characters to detect the end of a data field. By having these single quote characters expanded a correct SQL query is always created.
see also: &/2 delete/3 insert/3 is/2 replace/3 substring/3 string_list/2 to_prolog/1 to_string/1 to_upper/1 trim/1 triml/1 trimr/1 working with strings
| Examples | |
| X is_string expand_sq('a''s'). | succeeds and X is unified with an atom with two single quote
characters in it X = a''''s |
| Str is_string [97,39], Str2 is_string expand_sq(Str). |
succeeds, first is Str unified with an atom of two
characters: a', then the single quote in that string is doubled Str = a' Str2 = a'' |
| Exceptions | |
| The parameter is an empty variable | an instantiation_error exception is thrown |
| The parameter is a floating-point number | a type_error(callable, Arg) exception is thrown and Arg is replaced by the value of the parameter |