Here you can find the source of lengthMinusTrailingWhitespace(String line)
Parameter | Description |
---|---|
line | the string to process |
public static int lengthMinusTrailingWhitespace(String line)
//package com.java2s; // License as published by the Free Software Foundation; either public class Main { /**//from w w w . j a v a 2 s.co m * Returns the length of a string ignoring all trailing whitespace. It is a * pity that there is not a trim() like method that only removed the * trailing whitespace. * @param line the string to process * @return the length of the string ignoring all trailing whitespace **/ public static int lengthMinusTrailingWhitespace(String line) { int len = line.length(); for (int i = len - 1; i >= 0; i--) { if (!Character.isWhitespace(line.charAt(i))) { break; } len--; } return len; } }