Date: 02-16-2022
Return to Index
created by gbSnippets
'With a URL such as http://www.garybeene.com:80/sw/gbsnippets.htm in hand,
'it can be convenient to have access to the various parts of the URL: the
'protocol (http, ftp, https, ...), the domain (www.garybeene.com), the
'path "/sw/gbsnippets.htm" and the port "80".
'Primary Code
'Credit: Jeff Blakeney
http://www.powerbasic.com/support/pbforums/showthread.php?t=41414&highlight=Tcp+Print
'Starting with this full address:
URL$ = "http://www.garybeene.com/files/gbsnippets.msg"
sProtocol = UCase$(Extract$(sURL, "://")) 'protocol
sHost = Extract$(Remain$(sURL, "://"), ANY "/?") 'host name or IP address
sPath = Remain$(sURL, sHost) 'path and/or query being passed
sPort = IIF$(Instr(sHost, ":"), Remain$(sHost,":")) 'string version of port number, "" otherwise
If Len(sPort) Then sHost = Extract$(sHost, ":") 'take the port off the domain
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg as DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local URL$, sProtocol$, sHost$, sPath$, sPort$
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
URL$ = "http://www.garybeene.com:80/files/gbsnippets.msg"
URL$= "http://www.powerbasic.com/support/pbforums/showpost.php?p=322649" 'alternate example
sProtocol = UCase$(Extract$(URL$, "://")) 'protocol
sHost = Extract$(Remain$(URL$, "://"), ANY "/?") 'host name or IP address
sPath = Remain$(URL$, sHost) 'path and/or query being passed
sPort = IIF$(Instr(sHost, ":"), Remain$(sHost,":"),"") 'string version of port number, "" otherwise
If Len(sPort) Then sHost = Extract$(sHost, ":") 'take the port off the domain
MsgBox URL$ + $crlf + sProtocol + $crlf + sHost + $crlf + sPath + $crlf + sPort
End If
End Function
'gbs_00375
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm