标题:有关streamreader.read的问题,十六进制大于7F的处理,请指教。
只看楼主
pmmiao
Rank: 2
等 级:论坛游民
帖 子:9
专家分:40
注 册:2008-10-28
 问题点数:0 回复次数:1 
有关streamreader.read的问题,十六进制大于7F的处理,请指教。
做了个TCP侦听的程序,当获取数据后,对数据进行一个字一个字的读取,然后转换成十六进制,发现,当大于7F时,进来的就是FFFD,而不是80,并且总是在此处出错,请高手指教。相关代码如下:
            Dim a As String = ""
            While Listening '循环获取数据
                If isConnected = True Then
                   Try
                        Message = ""
                       Dim Reader As New StreamReader(tpClient.GetStream())
                        While Reader.Peek() >= 0
                            a = Hex(Reader.Read())
                            Message = Message & Microsoft.VisualBasic.Right("00" & a, 2) & " "
                        End While
                         Message = Trim(Message)
                         If Len(Message) > 2 Then
                             showMessage = Message
                             Me.demoThread = New Thread(New ThreadStart(AddressOf Me.ThreadProcSafe))
                             Me.demoThread.Start()
                         End If
                     Catch ex As Exception
                         isConnected = False
                         Thread.CurrentThread.Abort()
                         'MsgBox("连接错误。")
                     End Try
                 End If
             End While
怎么样才能处理大于7F的数据,谢谢了!!
搜索更多相关主题的帖子: 十六进制 
2011-05-21 01:02
pmmiao
Rank: 2
等 级:论坛游民
帖 子:9
专家分:40
注 册:2008-10-28
得分:0 
自己提出的问题,自己解决,这儿人气不行哦:
        While Listening
            Try
                Message = ""
                Dim Reader As NetworkStream = tpClient.GetStream()
                If Reader.CanRead Then
                    StreamDataNumber = tpClient.Available
                    ReDim bytes(StreamDataNumber - 1)
                    Reader.Read(bytes, 0, StreamDataNumber)
                    For i = 0 To StreamDataNumber - 1
                        Message = Message & Microsoft.VisualBasic.Right("00" & Hex(bytes(i)), 2)
                    Next
                End If
        End While
2011-05-22 09:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-340593-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.245386 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved