得到小的方形字符而不是文本 [英] Getting little square characters instead of Text

查看:86
本文介绍了得到小的方形字符而不是文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将SNMP SystemName查询发送到本地主机,作为响应,我得到的是很少的方形字符,而不是特定的系统名称..

设备SNMP信息:
sysName-数据类型:48,[] [] [] []

这是代码

 导入 System.Text

 Form1

     Dim  commlength  As   Integer ,miblength  As  整数,数据类型为 As   As   As  昏暗正常运行时间 As  整数
     Dim 输出 As   String 
     Dim  conn  As  新建 SNMP()
     Dim 响应 As   Byte ()= 新建 字节( 1023 ){}
    ' 公共共享子主程序(ByVal argv As String())
    ' 结束子


    私人  Form1_Load( ByVal 发​​件人 As 系统.对象 ByVal  e  As  System.EventArgs)句柄  MyBase  .Load
        IPaddress.Text = " 
        Community.Text = " 

    结束 

    私有  Button1_Click( ByVal 发​​件人 As 系统.对象 ByVal  e  As  System.EventArgs)句柄 Button1.Click

        ListBox1.Items.Add(" )

        ' 发送sysName SNMP请求
        响应= conn.[获取](" 、IPaddress.Text、Community.Text、" )
        如果响应( 0 )=& HFF >然后
            ListBox1.Items.Add(" & IPaddress.Text没有响应)
            返回
        结束 如果

        ' 如果响应,请获取社区名称和MIB长度
        commlength = Convert.ToInt16(response( 6 ))
        miblength = Convert.ToInt16(response( 23  + commlength))

        ' 从SNMP响应中提取MIB数据
        数据类型= Convert.ToInt16(response( 24  + commlength + miblength))
        datalength = Convert.ToInt16(response( 25  + commlength + miblength))
        datastart =  26  + commlength + miblength
        输出= Encoding.ASCII.GetString(响应,数据开始,数据长度)
        ListBox1.Items.Add(" & datatype& "  "&输出)

output = Encoding.UTF8.GetString(response,datastart,datalength)


我通过用UTF8替换Ascii来得到相同的盒子...当我用ASCII代替ASCII编写unicode时,我得到了一些无法识别的字符.底部有此代码

 ListBox1.Items.Add(" &数据类型& " & output)


会帮忙吗
添加"ToString"

 ListBox1.Items.Add(" & datatype.ToString& " & output)


I am sending SNMP SystemName query to local host and in response i m getting little square characters instead of the specific system name..

Device SNMP Information:
sysName - Datatype: 48, [][][][]

Here is the code

Imports System.Text

Class Form1

    Dim commlength As Integer, miblength As Integer, datatype As Integer, datalength As Integer, datastart As Integer
    Dim uptime As Integer
    Dim output As String
    Dim conn As New SNMP()
    Dim response As Byte() = New Byte(1023) {}
    'Public Shared Sub Main(ByVal argv As String())
    'End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        IPaddress.Text = "115.186.115.188"
        Community.Text = "public"

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ListBox1.Items.Add("Device SNMP information:")

        ' Send sysName SNMP request
        response = conn.[get]("get", IPaddress.Text, Community.Text, "1.3.6.1.2.1.1.5.0")
        If response(0) = &HFF Then
            ListBox1.Items.Add("No response from " & IPaddress.Text)
            Return
        End If

        ' If response, get the community name and MIB lengths
        commlength = Convert.ToInt16(response(6))
        miblength = Convert.ToInt16(response(23 + commlength))

        ' Extract the MIB data from the SNMP response
        datatype = Convert.ToInt16(response(24 + commlength + miblength))
        datalength = Convert.ToInt16(response(25 + commlength + miblength))
        datastart = 26 + commlength + miblength
        output = Encoding.ASCII.GetString(response, datastart, datalength)
        ListBox1.Items.Add("  sysName - Datatype:" & datatype & "," & output)

解决方案

Change your encoding from ASCII to UTF8 or Unicode and see what you get.

output = Encoding.UTF8.GetString(response, datastart, datalength)


I m getting same boxes by replacing Ascii with UTF8 ... and I m getting some unrecognizable characters when I wrote unicode in place of Ascii


I''m not sure why you are writing to the listbox 3 different times with 3 different items, but on the bottom there is this code

ListBox1.Items.Add("  sysName - Datatype:" & datatype & "," & output)


Will doing this help
Adding the "ToString"

ListBox1.Items.Add("  sysName - Datatype:" & datatype.ToString & "," & output)


这篇关于得到小的方形字符而不是文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆