List of utility methods to do Scanner Usage
String | getNextLine(final Scanner scanner) Skips comment lines while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (line.startsWith("//")) { continue; if (line.startsWith("/*")) { // multi line comment String skipLine = line; while (scanner.hasNextLine() && !skipLine.contains("*/")) { ... |
String | getNextLine(final Scanner source) Read lines from input java.util.Scanner until it finds a non-commented line, then send it back. String line; while (source.hasNextLine()) { line = source.nextLine(); if (line.startsWith(COMMENT_STRING)) { continue; } else { final int commentIndex = line.indexOf(COMMENT_STRING); if (commentIndex < 0) { ... |
String | getNextWord(Scanner scan) get Next Word String word = scan.nextLine();
return word.trim();
|
int | getNextWord(String str, int index, StringBuilder outToken, String ignoreRegex) Retrieves the next word in str .
if (index >= str.length()) return str.length(); String rem = str.substring(index, str.length()); Scanner s = new Scanner(rem); s.useDelimiter(ignoreRegex); String token = null; while (s.hasNext() && (token = s.next()).length() == 0) ; ... |
int | getNumberOfUsernames(String usernames) get Number Of Usernames Scanner scanner = new Scanner(usernames); scanner.useDelimiter(","); int i = 0; while (scanner.hasNext()) { scanner.next(); i++; return i; ... |
String | getOutputFromValgrindOutput(String valgrindOutput) get Output From Valgrind Output StringBuilder programOutput = new StringBuilder(); Scanner scanner = new Scanner(valgrindOutput); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (!line.startsWith("==")) { programOutput.append(line); programOutput.append(System.getProperty("line.separator")); return programOutput.toString(); |
String | getPartOfString(String string, int index, String delimiter) get Part Of String Scanner scanner = new Scanner(string).useDelimiter(delimiter); for (int i = 1; i < index; i++) { scanner.next(); return scanner.next(); |
String | getReplay(String prompt) get Replay Scanner scanner = new Scanner(System.in, "UTF-8"); System.out.println(prompt); String str = scanner.nextLine().trim(); scanner.close(); return str; |
String | getScannerContents(final Scanner scanner) get Scanner Contents String content; if (scanner.hasNext()) { content = scanner.next(); } else { content = ""; return content; |
String[] | getStrings(Properties props, String key, String sep) Gets an array of string properties given a key and a proper word separator. String val = props.getProperty(key); if (val == null || val.trim().equals("")) return new String[0]; ArrayList<String> l = new ArrayList<String>(5); Scanner s = new Scanner(val); s.useDelimiter(sep); while (s.hasNext()) { String v = s.next(); ... |