Results 1 to 11 of 11

Thread: [RESOLVED] How to seperate a string?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Resolved [RESOLVED] How to seperate a string?

    I need to know how to separate a line that the user types into a text box, and separate them by each character, and do something with that character. How would i do this? I also need to be able to calculate the total number of characters typed. Thanks.
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  2. #2
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: How to seperate a string?

    I would imagine the Split() function to split up your string and the Len() function to return the character count. Note: Len() counts spaces too!
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: How to seperate a string?

    Okay. After the split function, how would i assign the character to a variable?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How to seperate a string?

    Split function will place the results in an array.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: How to seperate a string?

    Oh. Ok. So like
    arrExample() = Split(txtExample.text)
    ?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  6. #6
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: How to seperate a string?

    Like this. Note the array as baja_yu stated.

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
       Dim strWords As String
       Dim strSplit() As String
       Dim i As Integer
       strWords = "A String comprised of six words"
       strSplit = Split(strWord, " ")                           ' split strWords at each space char.
       For i = 0 To UBound(strSplit)
          MsgBox strSplit(i)
       Next i
    End Sub
    Last edited by CDRIVE; Oct 8th, 2010 at 04:25 PM. Reason: Changed Var name to something more meaningful
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: How to seperate a string?

    how can i get it to split each character though? like if the word was "Hello" it would do H e l l and o.
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  8. #8
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How to seperate a string?

    Use Mid$ in a For loop instead of split for that.

    Code:
    For I = 1 To Len(Text1.Text)
       MsgBox Mid$(Text1.Text, I, 1)
    Next I

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: How to seperate a string?

    Sweet! That worked baja_yu. Thanks so much!
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  10. #10
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: How to seperate a string?

    Quote Originally Posted by Gamemaster1494 View Post
    how can i get it to split each character though? like if the word was "Hello" it would do H e l l and o.
    I should have read your first post more thoroughly. Mid(), as already stated by B_Y.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: [RESOLVED] How to seperate a string?

    Hehe. Thanks also CDRIVE. =)
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

Posting Permissions

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



Click Here to Expand Forum to Full Width