Java Zero Format zeroUnPad(String s)

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

Description

Left unPad with '0'

License

Open Source License

Parameter

Parameter Description
s - original string

Return

zero unPadded string

Declaration

public static String zeroUnPad(String s) 

Method Source Code

//package com.java2s;
/*//  w ww  .  j av  a2  s.  co m
 * jPOS Project [http://jpos.org]
 * Copyright (C) 2000-2019 jPOS Software SRL
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Left unPad with '0'
     * @param s - original string
     * @return zero unPadded string
     */
    public static String zeroUnPad(String s) {
        return unPadLeft(s, '0');
    }

    /**
     * Unpad from left. 
     * @param s - original string
     * @param c - padding char
     * @return unPadded string.
     */
    public static String unPadLeft(String s, char c) {
        int fill = 0, end = s.length();
        if (end == 0)
            return s;
        while (fill < end && s.charAt(fill) == c)
            fill++;
        return fill < end ? s.substring(fill, end) : s.substring(fill - 1, end);
    }
}

Related

  1. zeroThrough(int max)
  2. zeroToOne(float value, float min, float max)
  3. zeroToOne(long _min, long _max, long _value)
  4. zeroToSpace(String s)
  5. zeroToStr(String fStr, String lStr)
  6. zeroUnPad(String s)