-
Aug 1st, 2014, 03:55 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Create custom String Class with a custom Method
Hi Guys!
Code:
Public Class WebPage
Inherits String 'I know String is not inheritable
Private Method Url(address As String) As String 'I know there is no such thing
Dim wrGETURL As WebRequest
wrGETURL = WebRequest.Create(address)
Dim myProxy As New WebProxy("myproxy", 80)
myProxy.BypassProxyOnLocal = True
'wrGETURL.Proxy = myProxy
wrGETURL.Proxy = WebProxy.GetDefaultProxy()
Dim objStream As Stream
objStream = wrGETURL.GetResponse.GetResponseStream()
Dim objReader As New StreamReader(objStream)
Dim HtmlSource As String = ""
Do While Not HtmlSource Is Nothing
HtmlSource = objReader.ReadLine
If Not HtmlSource Is Nothing Then
HtmlSource &= HtmlSource
End If
Loop
Return HtmlSource
End Function
End Class
Private Sub GetSource()
Dim myPage As WebPage
Dim myString As String
mySource = myPage.Url("http://www.microsoft.com/en/us/default.aspx")
MsgBox(mySource)
End Sub
So I have 2 related questions:
1) How to create a custom String Class?
2) How to create a custom Method only belongs to this class?
Thanks a lot!
Last edited by Flashbond; Aug 1st, 2014 at 05:11 PM.
God, are you punishing me because my hair is better than yours? -Jack Donaghy
-
Aug 1st, 2014, 05:19 PM
#2
Thread Starter
Fanatic Member
Re: Create custom String Class with a custom Method
Yeah, I did it:
Code:
Imports System
Imports System.Net
Imports System.IO
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myString As WebPage = "Mert"
Dim mert As String = myString.Url("http://www.microsoft.com/en/us/default.aspx")
MsgBox(mert)
End Sub
End Class
Public Class WebPage
Private Sub New(ByVal value As String)
End Sub
Public Shared Widening Operator CType(ByVal value As String) As WebPage
Return New WebPage(value)
End Operator
Public Function Url(address As String) As String
Dim wrGETURL As WebRequest = WebRequest.Create(address)
Dim myProxy As New WebProxy("myproxy", 80)
myProxy.BypassProxyOnLocal = True
wrGETURL.Proxy = WebProxy.GetDefaultProxy()
Dim objStream As Stream = wrGETURL.GetResponse.GetResponseStream()
Dim objReader As New StreamReader(objStream)
Dim Stream As String = ""
Dim HtmlSource As String = ""
Do While Not Stream Is Nothing
Stream = objReader.ReadLine
If Not HtmlSource Is Nothing Then
HtmlSource &= Stream
End If
Loop
Return HtmlSource
End Function
End Class
God, are you punishing me because my hair is better than yours? -Jack Donaghy
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
|