Re: [eclipse-users] Howto include non-printable characters in String?

From: Kish Shen <kish.shen_at_crosscoreop.com>
Date: Tue, 12 Dec 2006 17:14:18 +0000
Hi,

On Tuesday 12 December 2006 15:25, Ulrich Scholz wrote:
> Hi,
> 
> I'd like to create a String that includes, e.g., newlines.  Is that
> possible?  And how?
> 
> Thank you,
> 
> Ulrich

Yes,  newlines and other characters can be specified in a string with an escape sequence, 
starting with \. \n is for new line, e.g.

[eclipse 3]: A = "one\ntwo", write(A).
one
two
A = "one\ntwo"

An example of such a string is shown in Chapter 3 (Prolog Introduction) of the 
ECLiPSe: A Tutorial Introduction document, and a specification of the escape sequence
is given in the User Manual, Escape Sequences within Strings and Atoms, in Appendix A.

If you are actually printing the string using printf/1,2, you can use %n to specify a new line,
instead of \n (%n is a control annotation for printft that specifies a new line, not an 
escape sequence). This has the advantage of printing a new line on all architecture (\n on its
own may not be printed as a newline, e.g. on Windows).

Cheers,

Kish
 
Received on Tue Dec 12 2006 - 17:13:35 CET

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:57 CET