我希望能够获得字符串中所有字符的ASCII值。 我可以得到一个字符的ASCII值,但我不能为整个字符串做。
我的尝试:
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))
我希望能够获取字符串中所有字符的ASCII值,这样我就可以更改字母表中+1字符串中的所有字母。 任何帮助表示感谢,谢谢。
答案 0 :(得分:1)
Dim asciis As Byte() = System.Text.Encoding.ASCII.GetBytes(input)
如果您想增加每个字母的ascii值,可以使用以下代码:
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)
答案 1 :(得分:1)
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
答案 2 :(得分:1)
我知道已经快三年了,但是让我向您展示一下。
用于将String转换为Ascii的函数(您的代码中已经有一个String)。您可以使用(Asc)或(Ascw) ...有关更多信息,请阅读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)
将Ascii转换为字符串的函数(您要的内容)。您可以使用(Chr)或(ChrW) ...有关更多信息,请阅读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