Are for-loops not allowed in callback functions?

Started by
12 comments, last by Wyrframe 7 years, 2 months ago

It sounds like you want to check for some condition every iteration and use the continue statement to skip your for-loop logic. Or you could use a previous for-loop to determine the index to start at.

Advertisement


For you, let the machine find the last "." and the last "x", and it gives you the area of interest, without magic counting from you. Takes a few micro-seconds, but these devices are never wrong :p


This. ???
It's called string splitting with delimiter.

if(resultCode==RESULT_OK){
//[...]
  int fileID = -1;
  int lastSlash = filePath.lastIndexOf('/');
  int extension = filePath.indexOf('.', lastSlash);

  if( extension > lastSlash ) {
    fileID = 0;
    for(int i = lastSlash + 1; i < extension; ++i) {
      char e = filePath.charAt(i);
      if( e >= '0' && e <= '9' ) {
        fileID = fileID * 10 + e - '0';
      }
    }
  }

  // If fileID is still -1, the path didn't end in a numerically-suffixed file.

//[...]
}

Lower cost than RegExp matching the file for the numeric part, but mind that it falls over if your terminal filename has multiple numeric sections (e.g. "photo-2017-01-02-000003456.jpg"); it treats all digits in the terminal filename as being part of the ID. No length assumptions (except that the file ID will fit in a 32-bit int), no spurious char[] or int[] allocation.

RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

This topic is closed to new replies.

Advertisement