String Manupilation - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

String Manupilation

DWDuckDWDuck Posts: 31Member
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 :)

Comments

  • DaiMitnickDaiMitnick Posts: 77Member
    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:
    [code]
    Dim StrStart As String = "123456"
    Dim StrEnd As String = ""

    For Each Ka As Char In StrStart
    StrEnd = Ka & StrEnd
    Next
    Debug.Print(StrStart & " - " & StrEnd)
    [/code]

    String +10:
    [code]
    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)
    Next
    Debug.Print(Str2)
    [/code]



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