преобразование из массива Byte в String, VB.NET
Dim strmContent As System.IO.Stream
Dim nLength As Long
Dim strContent As String
....
'nLength - Это длина содержимого strmContent
Dim Bytes(nLength) As Byte
Dim numBytesToRead As Integer = CInt(nLength)
Dim numBytesRead As Integer = 0
While numBytesToRead > 0
Dim n As Integer = strmContent.Read(Bytes, numBytesRead, numBytesToRead)
If n = 0 Then
Exit While
End If
numBytesRead += n
numBytesToRead -= n
End While
strmContent.Close()
' на этом этапе у меня в массиве Bytes, мой текст. мне его теперь надо присвоить strContent, что никак не удаёться, я и Format и CStr и New String() и т.п. пробовал, это не катит.
ХЕЕЛП!!! Как решить трабл???
Может у меня подход в корне не верный? я просто на С/C++ лабаю, и методы естессно оттуда :)
Цитата:
Originally posted by Arestov
Есть у меня IO.Stream читаю из него текст, этот текст мне нужен как String. Ф-ция Read читает тока в Byte(), хорошо, делаю массив Byte и загружаю всё, но как из этого массива получить String???:
Dim strmContent As System.IO.Stream
Dim nLength As Long
Dim strContent As String
....
'nLength - Это длина содержимого strmContent
Dim Bytes(nLength) As Byte
Dim numBytesToRead As Integer = CInt(nLength)
Dim numBytesRead As Integer = 0
While numBytesToRead > 0
Dim n As Integer = strmContent.Read(Bytes, numBytesRead, numBytesToRead)
If n = 0 Then
Exit While
End If
numBytesRead += n
numBytesToRead -= n
End While
strmContent.Close()
' на этом этапе у меня в массиве Bytes, мой текст. мне его теперь надо присвоить strContent, что никак не удаёться, я и Format и CStr и New String() и т.п. пробовал, это не катит.
ХЕЕЛП!!! Как решить трабл???
Может у меня подход в корне не верный? я просто на С/C++ лабаю, и методы естессно оттуда :)
Есть у меня IO.Stream читаю из него текст, этот текст мне нужен как String. Ф-ция Read читает тока в Byte(), хорошо, делаю массив Byte и загружаю всё, но как из этого массива получить String???:
Dim strmContent As System.IO.Stream
Dim nLength As Long
Dim strContent As String
....
'nLength - Это длина содержимого strmContent
Dim Bytes(nLength) As Byte
Dim numBytesToRead As Integer = CInt(nLength)
Dim numBytesRead As Integer = 0
While numBytesToRead > 0
Dim n As Integer = strmContent.Read(Bytes, numBytesRead, numBytesToRead)
If n = 0 Then
Exit While
End If
numBytesRead += n
numBytesToRead -= n
End While
strmContent.Close()
' на этом этапе у меня в массиве Bytes, мой текст. мне его теперь надо присвоить strContent, что никак не удаёться, я и Format и CStr и New String() и т.п. пробовал, это не катит.
ХЕЕЛП!!! Как решить трабл???
Может у меня подход в корне не верный? я просто на С/C++ лабаю, и методы естессно оттуда :)
Это Вам не С++. :)
Попробуй функцию Chr(). Переводит число от 0 до 255 в символ.