package routines; public class UserString { public static int Index(String string, String substring, Integer instance) { int index = -1; if (string == null) { return 0; } if (substring == null) { return 0; } if (substring.equals("")) { return 1; } if (instance == null) { throw new UnsupportedOperationException("Instance is supposed to be NOT NULL!!"); } if (!string.contains(substring)) { return 0; } index = string.indexOf(substring, 0); while (--instance > 0 && index != -1) { index = string.indexOf(substring, index + 1); } return ++index; } }
0 Comments