turning string into an array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bushnellweb
    New Member
    • Jan 2010
    • 48

    #1

    turning string into an array?

    I want to turn a string into an array like so...

    Code:
    dim str1
    str1 = "hello world"
    
    arr1(0) = "h"
    arr1(1) = "e"
    arr1(2) = "l"
    arr1(3) = "l"
    arr1(4) = "o"
    arr1(5) = " "
    arr1(6) = "w"
    arr1(7) = "o"
    etc.... you get the point
    I am trying to do this dynamically but for some reason i'm getting an error when i write

    Code:
    for i=0 to Len(str1)
         strTemp = Mid(str1, i, 1)
    next
    just assume i declared all those vars....any ideas? it doesnt seem to like my i variable in the Mid function
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    At no point do you seem to be taking the 1 character and putting it into one of the array indexes.

    you take the 1 character and put it into a temp string - then do nothing with strTemp... so it's lost.

    Of course this is a Convert method that will do this without the loop

    The home for technical questions and answers at Microsoft. Get started asking, answering, and browsing questions about products like .Net, Azure, or Teams.

    Comment

    • bushnellweb
      New Member
      • Jan 2010
      • 48

      #3
      sorry i didn't type all the code out...obviously I would have put strTemp into an array of letters, but the Mid() function didnt work within the loop using i as the start position. ANSWER:

      Code:
             redim pieArr(3)
      pieArr(0) = "pie1"
      pieArr(1) = "pie2"
      pieArr(2) = "pie3"
      
      
      for each pie in pieArr
      	Response.write(pie & "<br />")
      next
      
      
      dim strPie, pieArr2
      
      strPie = "blueberry pie"
      
      pieArr2 = Split(strPie)
      
      Response.write(pieArr2(0))
      Response.write(pieArr2(1))
      The split() function does what I was looking for ... thanks for the help
      Last edited by bushnellweb; May 4 '10, 03:27 PM. Reason: found answer

      Comment

      • bushnellweb
        New Member
        • Jan 2010
        • 48

        #4
        guess this wasnt really what i was asking but it was what i ultimately wanted to do

        Comment

        • MrMancunian
          Recognized Expert Contributor
          • Jul 2008
          • 569

          #5
          Originally posted by bushnellweb
          guess this wasnt really what i was asking but it was what i ultimately wanted to do
          And that's the service we are providing here folks! :-D

          Steven

          Comment

          Working...