Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The code I used:

Dim enc As New System.Text.UTF8Encoding()
TextBox.Text = enc.GetString(datas)

datas's type is Object that coming from a .dll file that contain some date such as "The web page address is www......"

but that code can't show all datas in textbox, only first letter (T) appear. what do i do?
Posted
Comments
_Zorro_ 4-Aug-11 12:47pm    
Can you inspect your object and check if you got all the data you need in it?
Don't you know what the real type is? Apparently UTF8Encoding.GetString() expects a byte[]

From msdn:

Public Overridable Function GetString ( _
bytes As Byte() _
) As String
Sergey Alexandrovich Kryukov 7-Aug-11 1:05am    
Why do you think datas is some meaningful UTF8 text? How is this related to Object type? It does not have anything to do with UTF8. The argument should be array of bytes (not characters, not any other object).

You need to show how you obtained datas.
--SA

1 solution

Kindly verify few things:

From you code:
VB
Dim enc As New System.Text.UTF8Encoding()
TextBox.Text = enc.GetString(datas)


place a line in between the two lines and see what you get:
VB
Dim enc As New System.Text.UTF8Encoding()
' You should receive a full text in "Output Window" if your data comes perfectly.
System.Diagnostic.Debug.Print(datas) 
TextBox.Text = enc.GetString(datas)


Also, please check MaxLength property of your TextBox. It should not 1.

Here is a sample code for how to use GetString():

VB
'Here data is converted to bytes for sending...
Dim datas As String = "The web page address is www.google.com"
Dim b() As Byte = Encoding.UTF8.GetBytes(datas.ToCharArray)


'Assume 'b' is a byte array coming from some .dll as in your case
'Here data is converted back to String USING GETSTRING()
Dim StreamData As String = Encoding.UTF8.GetString(b)
System.Diagnostics.Debug.Print(StreamData)
 
Share this answer
 

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