# VBForums CodeBank > CodeBank - Visual Basic .NET >  Convert String To and From Binary

## VB6Learner

Here is a simple code on how to convert string to Binary


```
            Dim Text As String = TextBox1.Text
            Dim oReturn As New StringBuilder
            Dim Separator As String = ("")
            For Each Character As Byte In ASCIIEncoding.ASCII.GetBytes(Text)
                oReturn.Append(Convert.ToString(Character, 2).PadLeft(8, "1"))
                oReturn.Append(Separator)
            Next
            TextBox2.Text = (oReturn.ToString)
```

Here is another simple code on how to convert binary to string


```
            Dim BinaryText As String = TextBox1.Text
            Dim Characters As String = Regex.Replace(BinaryText, "[^01]", "")
            Dim ByteArray((Characters.Length / 8) - 1) As Byte
            For Index As Integer = 0 To ByteArray.Length - 1
                ByteArray(Index) = Convert.ToByte(Characters.Substring(Index * 8, 8), 2)
            Next
            TextBox2.Text = (ASCIIEncoding.ASCII.GetString(ByteArray))
```

Comment what you all think of it!

----------

