Find position of a string in another string. For example your first string is 'careerstack' and the second string is 'stack' then the output should be 7.
public class Ques2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
String match = "kiran";
String text = "kiranhellooooookiran";
int i =0;
while((i=(text.indexOf(match,i)+1))>0)
System.out.println(i-1);
}
}
public class Ques2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
String match = "kiran";
String text = "kiranhellooooookiran";
int i =0;
while((i=(text.indexOf(match,i)+1))>0)
System.out.println(i-1);
}
}
No comments:
Post a Comment