Computer Science Canada

String \ characters.

Author:  Martin [ Sun Sep 26, 2004 12:08 pm ]
Post subject:  String \ characters.

Suppose that I have a function:

public void whatever (String x);

Now, if I had the function called as follows:

code:
whatever ("Hello
World
Here
I come");


What would x look like in this case? I imagine that it would be "Hello\nWorld\nHere\nI come"

Now, my second question, is do these escape characters (\n) cound as characters? What value would x.length return?

And finally, is there any way that I could do something like System.out.println (x) so that it shows all of the escape characters?

Thanks in advance,
Martin

Author:  Martin [ Sun Sep 26, 2004 12:12 pm ]
Post subject: 

Alright, I figured it out, except for the display of the escape characters.

Author:  wtd [ Sun Sep 26, 2004 5:51 pm ]
Post subject: 

code:
x.replaceAll("\n", "\\n")


: