VB2010读取指定字符串。 Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load '定义变量的类型很重要,关系到计数的开始,如果数整型,则开始的0不在计算之列,如果是字符串,则计算 Dim wIM, yIM As String TextBox1.Text = "123456789" wIM = TextBox1.Text '空格计算位数 yIM = M id(wIM, 6, 2) TextBox2.Text = yIM 'TextBox2.Text = Convert.ToInt32(yIM, 2) End Sub Private Sub Label3_Click(sender As System.Object, e As System.EventArgs) Handles Label3.Click End Sub Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged '将第6,第7个数转换为ASCII码,然后转化为2进制 Dim AIM, bIM As String Dim bttext As Byte() Dim strbin As String = "" AIM = TextBox1.Text bIM = Mid(AIM, 6, 2) TextBox2.Text = bIM bttext = System.Text.Encoding.UTF8.GetBytes(TextBox2.Text) For i = 0 To bttext.Length - 1 strBin = strBin & Convert.ToString(Int32.Parse(bttext(i)), 2).PadLeft(8, "0") Next i TextBox3.Text = strbin End Sub End Class id(wIM, 6, 2) TextBox2.Text = yIM 'TextBox2.Text = Convert.ToInt32(yIM, 2) End Sub Private Sub Label3_Click(sender As System.Object, e As System.EventArgs) Handles Label3.Click End Sub Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged '将第6,第7个数转换为ASCII码,然后转化为2进制 Dim AIM, bIM As String Dim bttext As Byte() Dim strbin As String = "" AIM = TextBox1.Text bIM = Mid(AIM, 6, 2) TextBox2.Text = bIM bttext = System.Text.Encoding.UTF8.GetBytes(TextBox2.Text) For i = 0 To bttext.Length - 1 strBin = strBin & Convert.ToString(Int32.Parse(bttext(i)), 2).PadLeft(8, "0") Next i TextBox3.Text = strbin End Sub End Class