split Last pattern - Android java.lang

Android examples for java.lang:String Split

Description

split Last pattern

Demo Code

import android.text.TextUtils;

public class Main{

    public static String[] splitLast(String target, String pattern) {
        int index = target.lastIndexOf(pattern);
        if (index == -1) {
            throw new RuntimeException("Pattern is not found.");
        }/*w w w .j  a  v  a 2  s. co m*/

        return new String[] { target.substring(0, index),
                target.substring(index + 1) };
    }

}

Related Tutorials