Reputation: 87
I have this string:
B='Dogs cats birds and fish'.
and i need it to appear in the format bellow:
Dogs,
cats,
birds,
and fish
Is there any possible way for this to happen?
I tried nl
as in:
B='Dogs,nl, cats,nl, birds,nl, and fish'.
and \n
as in:
B='Dogs,\n, cats,\n, birds,\n, and fish'.
to no avail
B='Dogs cats birds and fish'.
Upvotes: 7
Views: 12015
Reputation: 476740
The new line character works, you should use write/1
[swi-doc] to print the string to the console, like:
?- write('Dogs,\ncats,\nbirds,\nand fish').
Dogs,
cats,
birds,
and fish
true.
?- B = 'Dogs,\ncats,\nbirds,\nand fish', write(B).
Dogs,
cats,
birds,
and fish
B = 'Dogs,\ncats,\nbirds,\nand fish'.
If you unify a variable, the Prolog will print that variable as a string literal, not the content of the string.
Upvotes: 3