|
-
Aug 7th, 2000, 11:02 AM
#1
Thread Starter
Fanatic Member
Hello,
I have a text box and I want to be able to pick out just the words individualy.
I can get the number of spaces and the number of words but I am not quite sure how to get the actuall words.
if my string is this
"Hello, how are you doing?"
I want to be able to associate "hello" with the number 1
"how" with number two...ect.
I hope this makes sense to someone.
thanks
-
Aug 7th, 2000, 11:09 AM
#2
Fanatic Member
What version of VB do you have???
If you have VB 6 then use Split Function.
example:
Code:
Option Explicit
Private Sub Form_Load()
Dim strTest As String: strTest = "Hello, how are you doing?"
Dim strArray() As String
Dim I As Integer
strArray() = Split(strTest, " ", , vbTextCompare)
For I = 0 To UBound(strArray)
If Right(strArray(I), 1) = "," Then '//check for unwanted symbols like ,.:;)( etc
strArray(I) = Left(strArray(I), Len(strArray(I)) - 1)
End If
Next I
For I = 0 To UBound(strArray)
Debug.Print I + 1 & " - " & strArray(I)
Next I
End Sub
'It would print:
'1 - Hello
'2 - how
'3 - are
'4 - you
'5 - doing?
Hope this makes some sense
Post #505
[Edited by QWERTY on 08-07-2000 at 12:14 PM]
-
Aug 7th, 2000, 11:15 AM
#3
Frenzied Member
If you are using VB6 you can use the Split Function
Code:
Dim MyArray() As String
MyArray() = Split(Text1.Text," ")
Now MyArray(0) is the first word, MyArray(1) is the Second, etc
-
Aug 7th, 2000, 01:23 PM
#4
If you do not have VB6, you can write your own Split function.
Code:
Public Function Split(ByVal sIn As String, Optional sDelim As _
String, Optional nLimit As Long = -1, Optional bCompare As _
VbCompareMethod = vbBinaryCompare) As Variant
Dim sRead As String, sOut() As String, nC As Integer
If sDelim = "" Then
Split = sIn
End If
sRead = ReadUntil(sIn, sDelim, bCompare)
Do
ReDim Preserve sOut(nC)
sOut(nC) = sRead
nC = nC + 1
If nLimit <> -1 And nC >= nLimit Then Exit Do
sRead = ReadUntil(sIn, sDelim)
Loop While sRead <> ""
ReDim Preserve sOut(nC)
sOut(nC) = sIn
Split = sOut
End Function
Public Function ReadUntil(ByRef sIn As String, _
sDelim As String, Optional bCompare As VbCompareMethod _
= vbBinaryCompare) As String
Dim nPos As String
nPos = InStr(1, sIn, sDelim, bCompare)
If nPos > 0 Then
ReadUntil = Left(sIn, nPos - 1)
sIn = Mid(sIn, nPos + Len(sDelim))
End If
End Function
-
Aug 7th, 2000, 01:37 PM
#5
Thread Starter
Fanatic Member
thanks all
Wow, I think that was more info than I need right now.
thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|