Android Question Work with substring

stp

Active Member
Licensed User
Longtime User
How do i get from
code:
https://www.test.com/mysite/test.html
test.html ? :)
 

amykonio

Active Member
Licensed User
Longtime User
Are you looking for something like that?
B4X:
Dim s As String = $"https://www.test.com/mysite/test.html"$
    
Dim result() As String = Regex.Split("/", s)

If result.Length > 0 Then
    Log(result(result.Length - 1))
End If
Andreas.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
other;
Last segment of the route before a possible query string
B4X:
    Dim Text As String = $"https://www.test.com/mysite/test.html"$
    Dim Pattern As String = $"\/([^\/?#]+)(?:[?#]|$)"$
    Dim Matcher1 As Matcher = Regex.Matcher(Pattern,Text)
    If Not (Matcher1.Find) Then Return
    Log(Matcher1.Group(1))
1750076157063.png


Ex, With query string
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
😅
B4X:
Dim S As String = "https://www.test.com/mysite/test.html"
Log(S.Replace("https://www.test.com/mysite/", ""))
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
ooops My Bad. File.GetName doesn't exist in B4a. Sorry.
You can use this sub

 
Upvote 0
Top