stp Active Member Licensed User Longtime User Jun 16, 2025 #1 How do i get from[CODE lang="b4x" title="code"]https://www.test.com/mysite/test.html[/CODE] test.html ?
How do i get from[CODE lang="b4x" title="code"]https://www.test.com/mysite/test.html[/CODE] test.html ?
A amykonio Active Member Licensed User Longtime User Jun 16, 2025 #2 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
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.
klaus Expert Licensed User Longtime User Jun 16, 2025 #3 Or like this: B4X: Private s As String = "https://www.test.com/mysite/test.html" Private i As Int Private r As String i = s.LastIndexOf("/") r = s.SubString(i + 1) Log(r) Upvote 0
Or like this: B4X: Private s As String = "https://www.test.com/mysite/test.html" Private i As Int Private r As String i = s.LastIndexOf("/") r = s.SubString(i + 1) Log(r)
TILogistic Expert Licensed User Longtime User Jun 16, 2025 #4 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)) regex101: PCRE2 (PHP) Match Workspace Explore and test this PCRE2 (PHP) regular expression online. Understand the pattern with regex explanations, generate code, and export matches to CSV or JSON. regex101.com Ex, With query string regex101: PCRE2 (PHP) Match Workspace Explore and test this PCRE2 (PHP) regular expression online. Understand the pattern with regex explanations, generate code, and export matches to CSV or JSON. regex101.com Last edited: Jun 16, 2025 Upvote 0
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)) regex101: PCRE2 (PHP) Match Workspace Explore and test this PCRE2 (PHP) regular expression online. Understand the pattern with regex explanations, generate code, and export matches to CSV or JSON. regex101.com Ex, With query string regex101: PCRE2 (PHP) Match Workspace Explore and test this PCRE2 (PHP) regular expression online. Understand the pattern with regex explanations, generate code, and export matches to CSV or JSON. regex101.com
stevel05 Expert Licensed User Longtime User Jun 16, 2025 #5 Or even: B4X: Dim S As String = "https://www.test.com/mysite/test.html" Log(File.GetName(S)) Upvote 0
stevel05 Expert Licensed User Longtime User Jun 16, 2025 #6 stevel05 said: Log(File.GetName(S)) Click to expand... ooops My Bad. File.GetName doesn't exist in B4a. Sorry. Upvote 0
stevel05 said: Log(File.GetName(S)) Click to expand... ooops My Bad. File.GetName doesn't exist in B4a. Sorry.
aeric Expert Licensed User Longtime User Jun 16, 2025 #7 B4X: Dim S As String = "https://www.test.com/mysite/test.html" Log(S.Replace("https://www.test.com/mysite/", "")) Upvote 0
B4X: Dim S As String = "https://www.test.com/mysite/test.html" Log(S.Replace("https://www.test.com/mysite/", ""))
stevel05 Expert Licensed User Longtime User Jun 16, 2025 #8 stevel05 said: ooops My Bad. File.GetName doesn't exist in B4a. Sorry. Click to expand... In which case my fallback would be Klaus's answer. Upvote 0
stevel05 said: ooops My Bad. File.GetName doesn't exist in B4a. Sorry. Click to expand... In which case my fallback would be Klaus's answer.
A amykonio Active Member Licensed User Longtime User Jun 16, 2025 #9 stevel05 said: ooops My Bad. File.GetName doesn't exist in B4a. Sorry. Click to expand... While it may not work in b4a, it's a good answer for those using b4j. Upvote 0
stevel05 said: ooops My Bad. File.GetName doesn't exist in B4a. Sorry. Click to expand... While it may not work in b4a, it's a good answer for those using b4j.
DonManfred Expert Licensed User Longtime User Jun 16, 2025 #10 stevel05 said: ooops My Bad. File.GetName doesn't exist in B4a. Sorry. Click to expand... You can use this sub FileUtil SUBs SubName: GetFilename Description: Gets the Filename of Image or Page from Path Sub GetFilename(fullpath As String) As String Return fullpath.SubString(fullpath.LastIndexOf("/") + 1) End Sub ' ' Example Log(GetFilename("http://www.domain.tld/SomePage.html")) ' -> SomePage.html Tags... www.b4x.com Upvote 0
stevel05 said: ooops My Bad. File.GetName doesn't exist in B4a. Sorry. Click to expand... You can use this sub FileUtil SUBs SubName: GetFilename Description: Gets the Filename of Image or Page from Path Sub GetFilename(fullpath As String) As String Return fullpath.SubString(fullpath.LastIndexOf("/") + 1) End Sub ' ' Example Log(GetFilename("http://www.domain.tld/SomePage.html")) ' -> SomePage.html Tags... www.b4x.com
stp Active Member Licensed User Longtime User Jun 16, 2025 #11 Thank you. The solution from Klaus and Amykonio works for any link. Upvote 0