|
-
May 13th, 2001, 09:39 AM
#1
Thread Starter
New Member
Getting word before string
Hey.
I'm wanting to be able to manipulate a string. I can search for the second word of the string, but I need to manipulate both the searched for word, and the word before it, let me show you an example...
--------
>
Frosk asks, "any guards or colors?"
>
The dashing, jaunty song spins and dances as Zephore nimbly plays his flute.
GSrE
>
Reznock smiles.
>
Lord Myrkull just arrived.
Reznock nods to Hilaire.
--------
The string which I search for is 'asks, "', ans in this example I need to be able to manipulate the whole 'Frosk asks, "'.
How would I go about finding this string?
Thanks in advance.
--DaveP
-
May 13th, 2001, 10:22 AM
#2
Lively Member
Find out how far ASKS is into the string using LEN or something, then just take that and display those characters.
eg.
if its 10 letters into the string, then just take out the first 10
Hope that helps
-
May 13th, 2001, 10:23 AM
#3
Fanatic Member
Try this:
Code:
Private Sub Command1_Click()
Dim sString As String
Dim sStringArray() As String
sString = "Frosk asks, ""any guards or colors?"""
'split the string into an array (only works in VB6)
sStringArray = split(sString, " ")
'Loop around looking for word to change
For X = 0 To UBound(sStringArray)
If sStringArray(X) = "asks," Then Exit For
Next X
'change the word and the word before it
sStringArray(X - 1) = "Whatever" 'Change Frosk
sStringArray(X) = "Whatever" 'Change asks
For X = 0 To UBound(sStringArray)
sString2 = sStringArray(X) & " "
Next X
End Sub
Does this work - you may need to make it a tad more inteligent in picking words.
Rob
My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]
-
May 13th, 2001, 11:40 AM
#4
Thread Starter
New Member
Thanks Rob!
I used the basis of the code you supplied, and it works pretty well.
It misses the occasional one, but only when I seem to get a rapid succession of matches.
Thanks again 
--DaveP
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
|