String Manupilation

Good day reader

I want to know how to do a couple of things with strings for instance

turn 123456 into 654321

then I also want to change the asci value of a character.

Here follows the code that I thought would fdo both of the above, could you correct me?

First query

Dim Str1 as Strings = "123456"
Dim Str2() as char = str1.tochararray
Dim st3() as char
Dim I as integer
dim J as integer
dim K as integer

J = len(str1)
for i = 1 to len(str1)
K = J+1-I
str3(i) = Str2(K)
next i

Str1 = Str3

this should turn str1 into "654321"

Second query

Dim Str1 as String = "ABC"
Dim Str2() as char = str1.tochararray
Dim Str3() as Char
Dim I integer
Dim J integer = 20
DIm Ch as char

For I = 1 to len(str1)
ch = chr(asc(Str2(i)+10)
Str3(i) = ch
next i

Str1 = Str3

This should turn str1 into "KLM"

Can someone tell me where I went wrong (I come from a Delphi background, the direct translated code for delphi would have worked but for some reason it doesn't work in VB)

Darkwing Duck aka DWduck signing off :)


  • Hi Duck, first off, there are a few spelling and syntax errors in there so keep an eye out for that. You don't need to involve chars so heavily, the below codes will do what you're looking for. HTH, Dai

    Reverse string:
    Dim StrStart As String = "123456"
    Dim StrEnd As String = ""

    For Each Ka As Char In StrStart
    StrEnd = Ka & StrEnd
    Debug.Print(StrStart & " - " & StrEnd)

    String +10:
    Dim Str1 As String = "ABC", Str2 As String = ""
    Dim intChar As Integer
    For Each Ka As Char In Str1
    intChar = Asc(Ka) + 10
    Str2 &= Chr(intChar)

    Do or do not, there is no try. |
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion