dcsimg
Results 1 to 5 of 5

Thread: read string into array

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    8

    read string into array

    I have a textbox which contain 26 letters as a single word (no spaces)
    Converted that to a variable cipheralphabet =TexxtboxCipher.text (cipheralphabet variable was already defined as string)

    I want to read those letters into an array. I am very new to VB.net so this is probably something simple that I yet do not understand

    None of these work

    For counter = 0 To 25
    arrCipher(counter) = CipherAlphabet(counter + 1).ToString()
    Next

    For counter = 1 To 26
    arrCipher(counter -1 ) = CipherAlphabet(counter).ToString()
    Next

    For counter = 0 To len(cipheralphabet)
    arrCipher(counter) = CipherAlphabet(counter + 1).ToString()
    Next

    The following gives no error but I have no way to know whether it is correct

    For counter = 0 To 25
    arrCipher(counter) = CipherAlphabet.Substring(counter, 1)
    Next


    What am I doing wrong?

    Is there an easy way (one liner hopefully) to display the contents of an array to check for errors as you code?



    Also if you could recommend a video playlist or website that I can/should use as a reference guide I would truly appreciate it.

    Microsoft . Docs appears to think you understand what you are doing in order to understand what they write. Kind of redundant methinks, if you knew what you were doing you wouldn't use it, if you don't know what you are doing its the most beginner unfriendly way to help

    Thanks in advance
    Last edited by efanton; Aug 20th, 2019 at 05:38 PM.

  2. #2
    Addicted Member
    Join Date
    Nov 2011
    Posts
    212

    Re: read string into array

    If you need to work with individual characters of a string convert it to a character array

    Code:
            Dim CipherAlphabet As String = "ABCDEFG"
            Dim arrCipher() As Char = CipherAlphabet.ToCharArray
    Convert a charcter array to a string

    Code:
    Dim alphabet As New String(arrCipher)
    https://docs.microsoft.com/en-us/dot...-of-characters
    https://docs.microsoft.com/en-us/dot...of-char-values

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,991

    Re: read string into array

    Check for errors as you code, no, probably not, but as you debug there certainly is. If you aren't familiar with the debugger, it's time to learn. The first step is to set a breakpoint, which you can do with F9. You can set a breakpoint on any line of code that actually does something (not on comments, white space, or variable declarations that don't also assign to the variable). Once you have set a breakpoint, you will see a maroon line with a maroon ball in the left margin. Once you see where that maroon ball is, you won't need to use F9 anymore, as you can set breakpoints by clicking in the margin beside the line where you want the breakpoint, and you can clear breakpoints by clicking on the ball.

    When you have a breakpoint set, and run the code in debug mode, execution will stop at the breakpoint. At that time, you can examine the contents of any variable either by hovering the mouse over it, or clicking on it and pressing Shift+F9. You can also step forwards through the code with F10 or F11 (they do different things, but I'll leave that to you to figure out), and you can always resume execution with F5.

    So, with breakpoints and those few keys, you can see any variable at runtime, evaluate any expression, follow along with code execution, and watch how the variables change as a result of each line. There are more tools than just those, but those are the most important ones. Without them, you are guessing. With them, you can see what is happening every step of the way.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    8

    Re: read string into array

    Quote Originally Posted by Shaggy Hiker View Post
    Check for errors as you code, no, probably not, but as you debug there certainly is. If you aren't familiar with the debugger, it's time to learn. The first step is to set a breakpoint, which you can do with F9. You can set a breakpoint on any line of code that actually does something (not on comments, white space, or variable declarations that don't also assign to the variable). Once you have set a breakpoint, you will see a maroon line with a maroon ball in the left margin. Once you see where that maroon ball is, you won't need to use F9 anymore, as you can set breakpoints by clicking in the margin beside the line where you want the breakpoint, and you can clear breakpoints by clicking on the ball.

    When you have a breakpoint set, and run the code in debug mode, execution will stop at the breakpoint. At that time, you can examine the contents of any variable either by hovering the mouse over it, or clicking on it and pressing Shift+F9. You can also step forwards through the code with F10 or F11 (they do different things, but I'll leave that to you to figure out), and you can always resume execution with F5.

    So, with breakpoints and those few keys, you can see any variable at runtime, evaluate any expression, follow along with code execution, and watch how the variables change as a result of each line. There are more tools than just those, but those are the most important ones. Without them, you are guessing. With them, you can see what is happening every step of the way.
    Thank you so much. That's exactly what I need. Now I can see whether its the input or output to a computation that is giving the problem.
    Life has become so much easier now without having to second guess myself

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    8

    Re: read string into array

    Quote Originally Posted by Mc_VB View Post
    If you need to work with individual characters of a string convert it to a character array

    Code:
            Dim CipherAlphabet As String = "ABCDEFG"
            Dim arrCipher() As Char = CipherAlphabet.ToCharArray
    Convert a charcter array to a string

    Code:
    Dim alphabet As New String(arrCipher)
    https://docs.microsoft.com/en-us/dot...-of-characters
    https://docs.microsoft.com/en-us/dot...of-char-values
    Dim arrCipher() As Char = CipherAlphabet.ToCharArray

    I saw that and tried something similar to it, but I got the syntax wrong.

    Thanks for replying, I can now see where I made the mistake

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width