Java Reference
In-Depth Information
Hello
Hello
Hello
Hello
^C
$
I test it by entering the usual test string “Hello World,” which prints fine. Then “Hello” with
one space, and the space is deleted. With five spaces, exactly the five spaces go. With six or
more spaces, only five spaces go. A blank line comes out as a blank line (i.e., without throw-
ing an Exception or otherwise going berserk). I think it works!
while
while (( inputLine = is . readLine ()) != null
null ) {
int
int toRemove = 0 ;
for
for ( int
int i = 0 ; i < nSpaces && i < inputLine . length () &&
Character . isWhitespace ( inputLine . charAt ( i )); i ++)
++ toRemove ;
System . out . println ( inputLine . substring ( toRemove ));
}
Entering Nonprintable Characters
Problem
You need to put nonprintable characters into strings.
Solution
Use the backslash character and one of the Java string escapes.
Discussion
The Java string escapes are listed in Table 3-1 .
Search WWH ::




Custom Search