List of usage examples for java.lang String indexOf
public int indexOf(String str)
From source file:Main.java
public static void main(String[] args) { String name = "Java"; if (name.indexOf("Java") != -1) { System.out.println("Bravo Java!"); } else {/*from w ww . j a va 2 s.c om*/ System.out.println("Can't find Java"); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { String string = "I am Java"; int index = string.indexOf("dam"); // 1 }
From source file:Main.java
public static void main(String[] argv) throws Exception { String string = "I am Java"; boolean b = string.indexOf("I am") > 0; // true }
From source file:Main.java
public static void main(String[] args) { String[] ids = TimeZone.getAvailableIDs(); for (String id : ids) { int slash = id.indexOf('/'); String stripped = id.substring(slash + 1).replace("_", " "); System.out.println(stripped); }//from ww w. j a va2 s . co m }
From source file:Main.java
public static void main(String[] argv) throws Exception { String string = "this is a test"; int index = string.indexOf('a'); }
From source file:MainClass.java
public static void main(String args[]) { String s1 = "The total cost is $45.67"; int i1 = s1.indexOf('$'); String s2 = s1.substring(i1); System.out.println(s2);/*w w w . j a v a 2 s .co m*/ }
From source file:MainClass.java
public static void main(String[] arg){ String str = "abcde"; /*from w w w . j ava2 s .c o m*/ int index = 0; index = str.indexOf('c'); System.out.println(index); }
From source file:MainClass.java
public static void main(String[] arg) { String str = "abcde"; int index = 0; index = str.indexOf('c'); System.out.println(index);/* w w w. j a va 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { String strOrig = "A B C A"; int intIndex = strOrig.indexOf("B"); if (intIndex == -1) { System.out.println("not found"); } else {// w w w.j a v a2 s . c om System.out.println("Found " + intIndex); } int positionIndex = strOrig.indexOf("A", 2); System.out.println("after 2 is " + positionIndex); int lastIndex = strOrig.lastIndexOf("A"); System.out.println("Last index " + lastIndex); }
From source file:Main.java
public static void main(String[] args) { String str = new String("Apple"); int index = str.indexOf('p'); // index will have a value of 1 System.out.println(index);//from ww w .ja v a 2 s . c om index = str.indexOf("pl"); // index will have a value of 2 System.out.println(index); index = str.lastIndexOf('p'); // index will have a value of 2 System.out.println(index); index = str.lastIndexOf("pl"); // index will have a value of 2 System.out.println(index); index = str.indexOf("k"); // index will have a value of -1 System.out.println(index); }