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

13 Jun 2024 - 18:28 | Version 1 |

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 FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback
This website is using cookies. More info. That's Fine