Results 1 to 4 of 4
Thread: String indexOf
- 10-07-2009, 07:06 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 40
- Rep Power
- 0
String indexOf
hi...I want to find the index of "{" bracket in a string but it is showing -1 always why?
here is my code:
File file1 = new File("prob.txt");
//StringBuffer contents = new StringBuffer();
BufferedReader reader = null;
String text=null;
try
{
reader = new BufferedReader(new FileReader(file1));
while ((text = reader.readLine()) != null) {
String []splits1 = text.split(" \\s+." );
for(int j=0; j< splits1.length ;j++){
if(splits1[j].length() > 0 && splits1[j].charAt(0) == '1'&& splits1[j].charAt(1) == '0')
{
int h=splits1[j].indexOf('{');
System.out.println(h);
System.out.println(splits1[j]);
System.out.println("rashi");
}
}
}
}
MY string is:
10 3.94 4.87 7.27 9.34 11.78 13.44 15.99 (18.31) [23.21] .
I want to know the index of { and } bracket but it;s always showing -1...why.plz correct me??
- 10-07-2009, 07:23 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
That doesn't have any curly braces in it. In this case indexOf() returns -1.MY string is:
10 3.94 4.87 7.27 9.34 11.78 13.44 15.99 (18.31) [23.21] .
I want to know the index of { and } bracket but it;s always showing -1...why.plz correct me??
- 10-07-2009, 07:33 AM #3
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
- 10-07-2009, 07:33 AM #4
Member
- Join Date
- Oct 2009
- Posts
- 40
- Rep Power
- 0
Similar Threads
-
combine string[] into string like perl's join function
By tekberg in forum Advanced JavaReplies: 9Last Post: 02-23-2009, 01:05 PM -
Let eclipse warn about a semicolon after an if statement and string == string?
By foobar.fighter in forum EclipseReplies: 5Last Post: 01-11-2009, 10:12 AM -
tricky indexOf implementation -- Help!!
By definewebsites in forum New To JavaReplies: 3Last Post: 12-10-2007, 12:48 AM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM -
Help regarding indexOf
By gauravj in forum New To JavaReplies: 1Last Post: 07-10-2007, 01:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks