如何在VB.net中获取字符串的ASCII值 [英] How to get ASCII values of a string in VB.net

查看:623
本文介绍了如何在VB.net中获取字符串的ASCII值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够获得字符串中所有字符的ASCII值. 我可以获取字符的ASCII值,但不能对整个字符串都做到这一点.

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.

我的尝试:

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字符中的所有字母. 任何帮助表示感谢,谢谢.

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.

推荐答案

使用 Encoding.ASCII.GetBytes :

Dim asciis As Byte() = System.Text.Encoding.ASCII.GetBytes(input)

如果要增加每个字母的ascii值,可以使用以下代码:

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)

这篇关于如何在VB.net中获取字符串的ASCII值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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