Android Question Substract a part from a string

German Buchmuller

Member
Licensed User
Hi, is it possible to obtain only a part from a string? For example:
B4X:
Dim s as string
Dim value as int
s="http://hello.com/image1.png"
value= s - "http://hello.com/image.png" (so the end value would be 1)
Thanks
 

DonManfred

Expert
Licensed User
B4X:
Sub GetFilename(fullpath As String) As String
   Return fullpath.SubString(fullpath.LastIndexOf("/") + 1)
End Sub
' results in image1.png
B4X:
Sub GetBasename(fullpath As String) As String
   Dim filename As String
   filename = GetFilename(fullpath)
   Return filename.SubString2(0,filename.LastIndexOf("."))
End Sub
' Depends on: GetFilename
' Example
'Log(GetBasename("http://www.domain.tld/SomePage.html")) ' -> SomePage
You now just need to extract the number at the end
 

German Buchmuller

Member
Licensed User
B4X:
Sub GetFilename(fullpath As String) As String
   Return fullpath.SubString(fullpath.LastIndexOf("/") + 1)
End Sub
' results in image1.png
B4X:
Sub GetBasename(fullpath As String) As String
   Dim filename As String
   filename = GetFilename(fullpath)
   Return filename.SubString2(0,filename.LastIndexOf("."))
End Sub
' Depends on: GetFilename
' Example
'Log(GetBasename("http://www.domain.tld/SomePage.html")) ' -> SomePage
You now just need to extract the number at the end
Thank you very much!!! Worked perfectly for me
 
Top