|
-
Mar 24th, 2011, 10:00 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] how to get a value from part of a url ?
Hi i got few urls:
example:
Code:
http://www.somesite.com/m2/side/1234567891/DisplayDetails.wmt
in a listbox i want to extract part of the url for example this part:1234567891 from the url when clicking on any url in listbox and place 1234567891 in a textbox for further process.could any one show me how this can be done.Thanks
url example:
Code:
http://www.somesite.com/m2/side/1234567891/DisplayDetails.wmt
Last edited by tony007; Mar 24th, 2011 at 10:03 AM.
-
Mar 24th, 2011, 10:26 AM
#2
Re: how to get a value from part of a url ?
vb.net Code:
Dim urlAddress As String = "http://www.somesite.com/m2/side/1234567891/DisplayDetails.wmt" TextBox1.Text = Split(urlAddress, "/").FirstOrDefault(Function(x) IsNumeric(x) = True)
-
Mar 24th, 2011, 11:14 AM
#3
Re: how to get a value from part of a url ?
 Originally Posted by Pradeep1210
vb.net Code:
Dim urlAddress As String = "http://www.somesite.com/m2/side/1234567891/DisplayDetails.wmt" TextBox1.Text = Split(urlAddress, "/").FirstOrDefault(Function(x) IsNumeric(x) = True)
That is VB.Net code though, not VB6 (which is the forum)!
The idea is the same, you just need to do it slightly differently:
First step is to Split so you get an array with all bits of the URL
After that, if you always want the 4th/5th/n-th part of the URL, you can just get it directly from the array.
If you want the part of the URL which is always numeric, then loop through each element of the array checking if the value is numeric or not (that's what the VB.net code does above, just using newer functions).
Has someone helped you? Then you can Rate their helpful post. 
-
Mar 24th, 2011, 11:33 AM
#4
Thread Starter
Frenzied Member
Re: how to get a value from part of a url ?
i think i fixed it by doing first removing the /DisplayDetails.wmt then got the last part of url:
Code:
Dim withParts As String
Dim withoutParts As String
withParts = "http://www.somesite.com/m2/side/1234567891/DisplayDetails.wmt"
withoutParts = Replace(withParts, "/DisplayDetails.wmt", "")
MsgBox "Text after last / is " & Mid$(withoutParts, InStrRev(withoutParts, "/") + 1)
Last edited by tony007; Mar 24th, 2011 at 11:55 AM.
-
Mar 24th, 2011, 11:54 AM
#5
Hyperactive Member
Re: how to get a value from part of a url ?
I don't know if i got you well, but tell me does the following help you ?
VB Code:
Dim string1 As String
Dim string2 As String
Dim Result As String
Dim Position As Integer
string1 = "http://www.somesite.com/m2/side/1234567891/DisplayDetails.wmt"
string2 = "/"
'To get the position of the \ starting from right
Position = InStrRev(string1, string2, Len(string1))
'Result after removing the part of the string that comes after the last /
Result = Mid(string1, 1, Position)
' Result will be : "http://www.somesite.com/m2/side/1234567891/"
-
Mar 24th, 2011, 01:34 PM
#6
Re: how to get a value from part of a url ?
 Originally Posted by manavo11
That is VB.Net code though, not VB6 (which is the forum)!
The idea is the same, you just need to do it slightly differently:
First step is to Split so you get an array with all bits of the URL
After that, if you always want the 4th/5th/n-th part of the URL, you can just get it directly from the array.
If you want the part of the URL which is always numeric, then loop through each element of the array checking if the value is numeric or not (that's what the VB.net code does above, just using newer functions).
Sorry.. I posted in the wrong forum.
This is the VB6 equivalent:
vb Code:
Dim urlAddress As String
urlAddress = "http://www.somesite.com/m2/side/1234567891/DisplayDetails.wmt"
Dim parts() as String, part as String
parts = Split(urlAddress, "/")
For each part in parts
If IsNumeric(part) Then
TextBox1.Text = part
Exit For
End If
Next
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|