by Matthijs (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sun 27th August 2000
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
This piece of code will filter words out of a string or a whole line of words
' this one will filter out te a string of words
' ex: variable = getwordline("hello I am a programmer",2,4)
' Now te variable will contain: "I am a" (without ")
If str >= stp Then GoTo sameorlw
On Error GoTo sameorlw
Dim enkword(1 To 255) As String
Dim fullstring As String
Dim X As Integer
For X = str To stp
enkword(X) = getwordNR(zin, X)
If enkword(X) <> "" Then
fullstring = fullstring & enkword(X) & " "
End If
Next X
getwordline = Left(fullstring, Len(fullstring) - 1)
Exit Function
sameorlw:
If str = stp Then getwordline = getwordNR(zin, str)
End Function
Public Function getwordfrom(zin As String, woord As Integer)
' This function filters out the selected word and the foloing words
If woord > 254 Then GoTo einde
If woord = 1 Then GoTo one
zin = zin & " "
Dim wordno(1 To 255) As Integer
Dim wordt(1 To 255) As String
wordno(1) = 1
For X = 1 To 254
On Error GoTo einde
wordno(X) = InStr(wordno(X), zin, " ", vbTextCompare)
wordno(X + 1) = InStr(wordno(X), zin, " ", vbTextCompare) + 1
If X = woord Then
temp12 = Right(zin, Len(zin) - wordno(X - 1))
getwordfrom = Left(temp12, Len(temp12) - 1)
Exit Function
End If
Next X
Exit Function
einde:
getwordfrom = ""
Exit Function
one:
getwordfrom = zin
End Function
Public Function getwordNR(zin As String, woord As Integer)
' this function will filter out the selected word (up to 254 words)
' example: var1 = getwordNR("word one hi :P", 2)
' Now the Varialbe var1 contains: "one" (without ")
' this is because that is the second word
If woord > 254 Then GoTo einde
zin = zin & " "
Dim wordno(1 To 255) As Integer
Dim wordt(1 To 255) As String
wordno(1) = 1
For X = 1 To woord + 1
On Error GoTo einde
wordno(X) = InStr(wordno(X), zin, " ", vbTextCompare)
wordno(X + 1) = InStr(wordno(X), zin, " ", vbTextCompare) + 1
temp1 = Left(zin, wordno(X) - 1)
If X <> 1 Then
temp1 = Right(temp1, wordno(X) - 1 - wordno(X - 1))
End If
If X = woord Then
getwordNR = temp1
Exit Function
End If
Next X
Exit Function
einde:
getwordNR = ""
End Function
No comments have been posted about This piece of code will filter words out of a string or a whole line of words. Why not be the first to post a comment about This piece of code will filter words out of a string or a whole line of words.