Difference: CSC121F2024Lab08Hint3 ( vs. 1)

Revision 12024-06-13 - CathyBareiss

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="CSC121F2024Lab08"

Dealing with strings (esp. leading spaces and/or end of line)

Leading spaces

The easiest way to remove leading spaces (such as a tab or blank) is to use the trim() function. So as an example:
        line = datafile.nextLine();
        line = line.trim();

Dealing with the end of line

After reading a number, if the next input is to be a string on a new line, be sure to read the rest of the current line. Example:
        number = keyboard.nextInt();
        keyboard.nextLine();
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback