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.
Are for-loops not allowed in callback functions?
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement