Java Reference
In-Depth Information
String myName ;
public
public static
void main ( String [] argv ) {
GoodNewline jack = new
static void
new GoodNewline ( "Jack Adolphus Schmidt, III" );
jack . print ( System . out );
}
protected
protected void
void print ( PrintStream out ) {
out . println ( toString ());
// classname and hashcode
out . println ( myName );
// print name on next line
}
Alternatively, if you need multiple lines, you could return an array or List of strings.
Reading “Continued” Lines
Problem
You need to read lines that are continued with backslashes ( \ ) or that are continued with
leading spaces (such as email or news headers).
Solution
Use my IndentContLineReader or EscContLineReader classes.
Discussion
This functionality is likely to be reused, so it should be encapsulated in general-purpose
classes. I offer the IndentContLineReader and EscContLineReader classes.
EscContLineReader reads lines normally, but if a line ends with the escape character (by de-
fault, the backslash), the escape character is deleted and the following line is joined to the
preceding line. So if you have lines like this in the input:
Here is something I wanted to say:\
Try and Buy in every way.
Go Team!
Search WWH ::




Custom Search