Click here to Skip to main content
16,012,166 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I want parse or convert ;rb(7167) As Byte to String.

My code example is below:

VB
Sub help()
    Dim HttpWebRequest As HttpWebRequest, HttpWebResponse As HttpWebResponse
    HttpWebRequest = WebRequest.Create("http://www.google.com")
    HttpWebResponse = HttpWebRequest.GetResponse
    Dim rb(64) As Byte
    Dim tbr As Integer
    tbr = HttpWebResponse.GetResponseStream.Read(rb, 0, 65)
    Dim Str As String = ""
    'I did
    For i = 0 To tbr-1
        Str = Str & Strings.Chr(rb(i))
    Next
    'But i need some thing simple and full data.
End Sub
Posted
Updated 17-Mar-11 3:08am
v4
Comments
CPallini 17-Mar-11 9:10am    
Where is the question?
[no name] 17-Mar-11 9:18am    
What error it shows?
Sergey Alexandrovich Kryukov 17-Mar-11 17:00pm    
By the way, use string.Empty, not "".
--SA

Have a look at the example on msdn. That will help you out:
http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx[^]

Good luck!
 
Share this answer
 
Comments
AHBB 17-Mar-11 10:14am    
thanks. my 5
Espen Harlinn 17-Mar-11 10:24am    
Nice link, my 5
A side advice: your code shows very poor performance in string concatenation "&". Your should always use Text.StringBuilder.Append for such purposes.

Here is why.
Strings are immutable. It means that string concatenation never modifies a string. Like in all string operations, a brand new string is created and the content of tho other strings are copied. If you do this in cycle, your ever-increasing target string instance is re-created with full copy of the previous result over and over. Text.StringBuilder.Append really modifies the instance of the StringBuilder, so it solves the problem efficiently.

By the way, string.Format is also more efficient for one-time operation, but should not be used in cycle, where only Text.StringBuilder does a good job.

As I already said, don't use "", use string.Empty.

—SA
 
Share this answer
 
Comments
Espen Harlinn 17-Mar-11 19:17pm    
While I agree on your notes on StringBuilder, he currently has a stream containing the html returned by his request, so I guess wrapping the stream in a System.IO.TextReader would be a nice solution. Your suggestion would still do wonders for the performance, so my 5
Sergey Alexandrovich Kryukov 17-Mar-11 22:07pm    
Thank you for understanding and your vote. I completely agree. My advices simply addressed the OP's code in front of me.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900