Get substring After separator - Java java.lang

Java examples for java.lang:String Substring

Description

Get substring After separator

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String sourceStr = "java2s.com";
        String expr = ".";
        System.out.println(substringAfter(sourceStr, expr));
    }//from  w  w w  .  j  a  v a 2s .c  o m

    public static String substringAfter(String sourceStr, String expr) {
        if (isEmpty(sourceStr) || expr == null) {
            return sourceStr;
        }
        if (expr.length() == 0) {
            return sourceStr;
        }

        int pos = sourceStr.indexOf(expr);
        if (pos == -1) {
            return sourceStr;
        }
        return sourceStr.substring(pos + expr.length());
    }

    public static boolean isEmpty(String chkStr) {
        if (chkStr == null) {
            return true;
        } else {
            return "".equals(chkStr.trim()) ? true : false;
        }
    }
}

Related Tutorials