Working with ansi codes in vb.net
I ran into a problem while writing a program for a school that converts a type string abc
to bcd
, a
becomes b
and b
becomes c
, and you can see the rest.
For i = 0 To length - 1
If (Asc(justatext.Substring(i, 1)) >= 65 And Asc(justatext.Substring(i, 1)) <= 90) Then
Asc(justatext.Substring(i, 1) = (Asc(justatext.Substring(i, 1) + 1)))
answer &= justatext.Substring(i, 1)
End If
Next
This is a function and I return a value answer
, but I always get it invalid cast exception
. Is there a way to do this with ansi
codes ?.
source to share
Your problem can be found in parentheses, you have quite a few of them and I think you confused yourself with them.
I turned off your code and removed the parentheses that are not needed:
For i = 0 To justatext.Length - 1
If Asc(justatext.Substring(i, 1)) >= 65 And Asc(justatext.Substring(i, 1)) <= 90 Then
answer &= Chr(Asc(justatext.Substring(i, 1)) + 1)
End If
Next
Beware: this code will only work for capital letters.
source to share