Results 1 to 4 of 4

Thread: String indexOf

  1. #1
    ras_pari is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Question 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??

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,708
    Rep Power
    13

    Default

    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??
    That doesn't have any curly braces in it. In this case indexOf() returns -1.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    Quote Originally Posted by pbrockway2 View Post
    That doesn't have any curly braces in it. In this case indexOf() returns -1.
    Of course, I don't know what he expected the index of a non-existant character to be.

  4. #4
    ras_pari is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

Similar Threads

  1. combine string[] into string like perl's join function
    By tekberg in forum Advanced Java
    Replies: 9
    Last Post: 02-23-2009, 02:05 PM
  2. Replies: 5
    Last Post: 01-11-2009, 11:12 AM
  3. tricky indexOf implementation -- Help!!
    By definewebsites in forum New To Java
    Replies: 3
    Last Post: 12-10-2007, 01:48 AM
  4. Replies: 0
    Last Post: 11-20-2007, 05:59 PM
  5. Help regarding indexOf
    By gauravj in forum New To Java
    Replies: 1
    Last Post: 07-10-2007, 01:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •