Reputation: 51
I want to be able so get the ASCII values of all the characters in a string. I can get the ASCII value of a character but i cannot do it for the whole string.
My attempt:
dim input as string = console.readline()
dim value as integer = ASC(input)
'Then I am changing its value by +1 to write the input in a secret code form.
console.writeline(CHR(value+1))
I want to be able to get the ASCII values for all characters in the string so i can change the all letters in the string +1 character in the alphabet. Any help appreciated, thanks.
Upvotes: 3
Views: 54597
Reputation: 194
I know it's been almost three years now, but let me show you this.
Function to convert String to Ascii (You already have a String in your Code). You can use either (Asc) or (Ascw) ... for more information, please read Microsoft Docs
Dim Input As String = console.readline()
Dim Value As New List(Of Integer)
For Each N As Char In Input
Value.Add(Asc(N) & " ")
Next
Dim OutPutsAscii As String = String.Join(" ", Value)
Function to Convert Ascii to String (What you asked for). You can use either (Chr) or (ChrW) ... for more information, please read Microsoft Docs
Dim Value1 As New List(Of Integer)
Dim MyString As String = String.Empty
For Each Val1 As Integer In Value1
MyString &= ChrW(Val1)
Next
Upvotes: 1
Reputation: 11
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim a As Integer
a = Asc(TextBox1.Text)
MessageBox.Show(a)
End Sub
End Class
Upvotes: 1
Reputation: 460068
Dim asciis As Byte() = System.Text.Encoding.ASCII.GetBytes(input)
If you want to increase each letter's ascii value you can use this code:
For i As Int32 = 0 To asciis.Length - 1
asciis(i) = CByte(asciis(i) + 1)
Next
Dim result As String = System.Text.Encoding.ASCII.GetString(asciis)
Upvotes: 2