Java Scanner Usage trim(String s)

Here you can find the source of trim(String s)

Description

Removes all ending \r and/or \n

License

Open Source License

Declaration

private static String trim(String s) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Scanner;

public class Main {
    /**//from   ww  w  .  j  ava 2  s  .  c o m
     * Removes all ending \r and/or \n
     */
    private static String trim(String s) {
        if (s == null)
            return null;
        Scanner scanner = new Scanner(s);
        String res = "";
        while (scanner.hasNextLine()) {
            if (!res.equals("")) {
                res = res + "\n";
            }
            res = res + scanner.nextLine();
        }
        return res;
    }
}

Related

  1. termInput()
  2. Tokenize(String s, String s2, String s3)
  3. toNumeric(String ip)
  4. toWords(String content)
  5. transformTXTandANNtoRQS(String TXT, String ANN)
  6. validateInt(Scanner keyboard, String message, String error)
  7. waitForEnter()
  8. waitForStopSignal()
  9. wrap(String msg, int wrapWidth, int wrapTolerance)