[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.
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!
Re: How to seperate a string?
Okay. After the split function, how would i assign the character to a variable?
Re: How to seperate a string?
Split function will place the results in an array.
Re: How to seperate a string?
Oh. Ok. So like
arrExample() = Split(txtExample.text)
?
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
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.
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
Re: How to seperate a string?
Sweet! That worked baja_yu. Thanks so much!
Re: How to seperate a string?
Quote:
Originally Posted by
Gamemaster1494
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.
Re: [RESOLVED] How to seperate a string?
Hehe. Thanks also CDRIVE. =)