Abstract
This chapter describes the principal techniques of string processing in Prolog, based on converting from atoms to lists and vice versa. The techniques are illustrated with examples of user-defined predicates to meet common string processing requirements.
After reading this chapter you should be able to:
-
Use a built-in predicate to convert strings of characters to lists and vice versa
-
Define predicates for the most common types of string processing
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Practical Exercise 10
Practical Exercise 10
-
(1)
Define and test a predicate spalindrome to check whether a string is a palindrome, e.g.
-
?- spalindrome(’abcd dcba’).
-
yes
-
?- spalindrome(’xyz’).
-
no
-
(2)
Use the name predicate to define and test a predicate remove_final that removes any final spaces from a string, e.g.
-
?- remove_final(’hello world ’,X).
-
X = ’hello world’
-
?- remove_final(’hello world’,X).
-
X = ’hello world’
-
(3)
Define and test a predicate replace to replace the first character in a string by the character ? (which has ASCII value 63), e.g.
-
?- replace(’abcde’,X).
-
X = ’?bcde’
Rights and permissions
Copyright information
© 2013 Springer-Verlag London
About this chapter
Cite this chapter
Bramer, M. (2013). String Processing. In: Logic Programming with Prolog. Springer, London. https://doi.org/10.1007/978-1-4471-5487-7_10
Download citation
DOI: https://doi.org/10.1007/978-1-4471-5487-7_10
Published:
Publisher Name: Springer, London
Print ISBN: 978-1-4471-5486-0
Online ISBN: 978-1-4471-5487-7
eBook Packages: Computer ScienceComputer Science (R0)