Tags:
create new tag
view all tags

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();
Topic revision: r1 - 2024-06-13 - CathyBareiss
 
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