Il metodo più veloce è:
codice:
Se MS è il tuo memorystream
Dim buffer(MS.Length) As Byte
MS.Read(buffer, 0, MS.Length)
dim MyString as String = System.Text.Encoding.UTF8.GetString(buffer)
MS.close
tuttavia sei soggetto alla codifica UTF8 (in questo caso) che potrebbe decodificarti male alcuni caratteri, come il § o altri.
Io per ovviare a questo problema generalmente uso questa funzioncina:
codice:
Se MS è il tuo memorystream
Dim buff(1024) As Byte
Dim nbytes = -1
Dim Stringa As String = ""
While nbytes <> 0
nbytes = MS.Read(buff, 0, buff.Length)
If nbytes = 0 Then Exit While
For Each SingoloByte As Byte In buff
If SingoloByte = 0 Then Exit For
Stringa += Chr(SingoloByte)
Next
End While
MS.Close()