remove Right Pad from String - Java java.lang

Java examples for java.lang:String Pad

Description

remove Right Pad from String

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "java2s.com";
        String pad = "com";
        System.out.println(removeRightPad(str, pad));
    }//from w  ww  .  j  ava  2  s.  c  om

    public static String removeRightPad(String str, String pad) {
        while (str.endsWith(pad)) {
            str = str.substring(0, str.lastIndexOf(pad));
        }
        return str;
    }
}

Related Tutorials