我创建了一些需要用户输入(这是一个字符串)并将每个字母更改为字母表中13个字母形式的代码。但我已经明白了文字的长度。但是我不知道如何在每次将一个字母改成字母表中的第13个字母时将变量加1。Vb.net将字符串中的所有字母更改为不同的字母
Dim looped As Integer
Dim length As Integer
Dim text As String
Dim newtext As String
Sub Main()
Console.WriteLine("Enter some text")
text = Console.ReadLine
looped = 0
text = LCase(text)
length = Len(text)
For counter = 1 To 25 Step 1
text = text.Replace("a", "n")
text = text.Replace("b", "o")
text = text.Replace("c", "p")
text = text.Replace("d", "q")
text = text.Replace("e", "r")
text = text.Replace("f", "s")
text = text.Replace("g", "t")
text = text.Replace("h", "u")
text = text.Replace("i", "v")
text = text.Replace("j", "w")
text = text.Replace("k", "x")
text = text.Replace("l", "y")
text = text.Replace("m", "z")
text = text.Replace("n", "a")
text = text.Replace("o", "b")
text = text.Replace("p", "c")
text = text.Replace("q", "d")
text = text.Replace("r", "e")
text = text.Replace("s", "f")
text = text.Replace("t", "g")
text = text.Replace("u", "h")
text = text.Replace("v", "i")
text = text.Replace("w", "j")
text = text.Replace("x", "k")
text = text.Replace("y", "l")
text = text.Replace("z", "m")
Next
Console.WriteLine(text)
Console.ReadLine()
End Sub
您需要遍历文本并分别替换每个字符。你可能会发现这段代码很有用:'Convert.ToInt32(ch)' – Neal
1)这里有一点问题。说你的文字是“a”。所以它被替换为“n”。然后将“n”替换为“a”。 2)提示:搜索“ROT13”。 –
[简单的rot13编码器在vb.net]可能的重复(http://stackoverflow.com/questions/13016727/simple-rot13-encoder-in-vb-net) –