title: Extracting substring
body: <p>i have some problems extracting strings</p>
  
  <p>i am making a multiple choice with 4 choices (e.g. as buttons), with the choices by referencing to the filename. The file (i.e. the question) is a png and the filename is Number-Q01AZ7BZ8CZ9DZ10ANZ8.png. These png are put under assets folder.</p>
  
  <pre><code>     Set&lt;String&gt; regions = regionsMap.keySet(); // get Set of regions
  
       // loop through each region
       for (String region : regions) 
       {
          if (regionsMap.get(region)) // if region is enabled
          {
             // get a list of all flag image files in this region
             String[] paths = assets.list(region);
  
             for (String path : paths) 
                fileNameList.add(path.replace(".png", ""));
          } // end if
       } // end for
  
  String fileName = fileNameList.get(randomIndex);
  
  if (!quizCountriesList.contains(fileName)) 
  {
     quizCountriesList.add(fileName); // add the file to the list
  
     String nextImageName = quizCountriesList.remove(0);
     correctAnswer = nextImageName; // update the correct answer
  
     int AZ = correctAnswer.indexOf("AZ");
     int BZ = correctAnswer.indexOf("BZ");
     int CZ = correctAnswer.indexOf("CZ");
     int DZ = correctAnswer.indexOf("DZ");
     int ANZ = correctAnswer.indexOf("ANZ");          
  
     String choiceA = null;
     String choiceB = null;
     String choiceC = null;
     String choiceD = null;
  
     choiceA = correctAnswer.substring( (AZ+2), (BZ) );
     choiceB = correctAnswer.substring( (BZ+2), (CZ) );
     choiceC = correctAnswer.substring( (CZ+2), (DZ) );
     choiceD = correctAnswer.substring( (DZ+2), (ANZ) );  
  </code></pre>
  
  <p>The logcat is as follows:</p>
  
  <pre><code>11-09 21:14:08.495: E/AndroidRuntime(25905): FATAL EXCEPTION: main
  11-09 21:14:08.495: E/AndroidRuntime(25905): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.trial.quizgame/com.trial.quizgame.QuizGame}: java.lang.StringIndexOutOfBoundsException: length=15; regionStart=1; regionLength=-2
  11-09 21:14:08.495: E/AndroidRuntime(25905):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
  </code></pre>
  
  <p>I have tried to set the buttons as .setText(correctAnswer) and it will correctly show as Number-Q01AZ7BZ8CZ9DZ10ANZ8, so the top part of getting the String for "correctAnswer" should be ok. The problem left at extracting strings, yet BZ must be at a position behind AZ, so as CZ behind BZ, etc:</p>
  
  <p>From the logcat the regionLength is -2? How could I handle this?
  I would like it to be for Q01, choice A=7, B=8, C=9, D=10 and ANZ=8</p>
  
  <p>thanks in advance for your advice!</p>