I though that this string function would only return -1 if the index was not found.
e.g.
B4X:
Sub SplitFF(S As String)
Dim p As Int
Try
p = S.LastIndexOf("/")
'Msgbox(p,"")
If p <> -1 AND p <> 64 Then
CodeModule.sFolder = S.SubString2(0, p)
CodeModule.sFileName = S.SubString(p + 1)
CodeModule.sFileNameShortName = CodeModule.sFileName.SubString2(0, CodeModule.sFileName.IndexOf("."))
End If
Catch
Msgbox(LastException.Message,"SplitFF Sub")
End Try
End Sub
if '/' is NOT found, S.LastIndexOf("/") returns 64 NOT -1.
I tried it and if the search pattern is not found it returns -1.
So if you get 64 that means that there is the search pattern at position 64.
You should either set a breakpoint or a Log in the code to check what happens.
Sub SplitFF(S As String)
'Looking for a file with an EXTENSION
'Albumthumb files have NO EXTENSIONS
'e.g. /mnt/sdcard/Android/data/com.android.providers.media/albumthumbs/1332740980099
' *** 64 ***
' 01234567890123456789012345678901234567890123456789012345678901234
Dim p, q As Int
Try
p = S.LastIndexOf("/")
If p <> -1 Then
q = S.LastIndexOf(".")
If q <> -1 Then
If q > p Then
CodeModule.sFolder = S.SubString2(0, p)
CodeModule.sFileName = S.SubString(p + 1)
'albumthumb file would CRASH here! except for condition: If q > p Then
CodeModule.sFileNameShortName = CodeModule.sFileName.SubString2(0, CodeModule.sFileName.IndexOf("."))
End If
End If
End If
Catch
Msgbox(LastException.Message,"SplitFF Sub")
End Try
End Sub
Hi Erel
LastindexOf is not giving correct results for some strings ..
str = "/storage/sdcard1/DCIM/Year 2014/10842290_10205387227779801_457166052324295608_o.jpg"