Hello, I'm trying to write a simple program to finde words betwen statments like <int></int>.
I converted String stream to a charArray, to get indexes of chars in the string.
public void foo(){
bucket=str.toCharArray();
System.out.println(str.substring(548,563));
System.out.println(str.substring(644,656));
System.out.println(str.substring(844,857));
System.out.println(str.substring(942,954));
System.out.println(str.length());
for(int i=0;i<str.length();i++){
if(bucket[i+0]==':' &&
bucket[i+1]=='i' &&
bucket[i+2]=='n' &&
bucket[i+3]=='t' &&
bucket[i+4]=='>' ){
index1=i+5;
System.out.println(index1);
}
if(bucket[i+0]=='/' &&
bucket[i+1]=='i' &&
bucket[i+2]=='n' &&
bucket[i+3]=='t' &&
bucket[i+4]=='>' ){
index2=i-1;
System.out.println(index2);
}
}
System.out.println(str.substring(index1, index2));
}
OUTCOME :
2567</type:int>
5</type:int>
34</type:int>
1</type:int>
986
548
563
644
656
844
857
942
954
java.lang.StringIndexOutOfBoundsException: String index out of range: -954
So, as you see:
System.out.println(str.substring(548,563));
System.out.println(str.substring(644,656));
System.out.println(str.substring(844,857)); WORKS !!!!!!!!
System.out.println(str.substring(942,954));
-------------------------------------------
System.out.println(str.substring(index1, index2)); DOESN'T WORK !!!!!
^^^^------ I need it, to work like this.
Dont know what work I'm doing with the substring.
Plz help.