Here you can find the source of stripTrailingChar(String input, char c)
Parameter | Description |
---|---|
input | String to remove from, if null returns null |
c | character to match |
public static String stripTrailingChar(String input, char c)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { /**/* w w w . j a v a 2s . c o m*/ * Removes a single character from the end of a string if it matches. * @param input String to remove from, if null returns null * @param c character to match * @return Original string minus matched character */ public static String stripTrailingChar(String input, char c) { if (input == null) return null; if (input.isEmpty()) return input; char[] charArray = input.toCharArray(); if (charArray[charArray.length - 1] == c) { return new String( Arrays.copyOf(charArray, charArray.length - 1)); } else { return input; } } }