Skip to main content

String Processing

  • Chapter
  • First Online:
Logic Programming with Prolog
  • 3290 Accesses

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

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

eBook
USD 16.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 16.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Practical Exercise 10

Practical Exercise 10

  1. (1)

    Define and test a predicate spalindrome to check whether a string is a palindrome, e.g.

  • ?- spalindrome(’abcd dcba’).

  • yes

  • ?- spalindrome(’xyz’).

  • no

  1. (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’

  1. (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

Reprints 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)

Publish with us

Policies and ethics