[RESOLVED] help to chang my code....please
I have this code to search a text file and get some information which are between two plus signs and it need some changes to get the exact information that I need
VB Code:
If UCase(Left(tmp(x + 1), 12)) = " (GLOSS)" Then
gloss = Split(tmp(x + 1), "+")
sLine = sLine & " (" & Trim(gloss(1)) & ");" ' here we add () for the traslation
Else
sLine = sLine & Left(Words(1), InStr(Words(1), ")") - 1) & ";"
End If
If this was a part of the text file
(GLOSS): with/by + the + cooperation +
.
.
(GLOSS): + with +
.
.
(GLOSS): the + collective + [fem.sg.]
.
.
(GLOSS): you [masc.sg.] + be taken/be adopted +
What I need is to get is the info between the last two + signs
It means I need the word red color
Cooperation
with
collective
be taken/be adopted
and this code gives me the first words between + signs which is wrong n the first line
the
with
collective
be taken/be adopted
Re: help to chang my code....please
maybe this will work for you
VB Code:
sLine = sLine & " (" & Trim(gloss(UBound(gloss) - 1)) & ");"
Re: help to chang my code....please
If all you need is the info from between the last two plus signs, make it search for it in reverse(if that is the end if the text you are searching, I mean) using InStrRev. But what you could do Kind of like this:
VB Code:
Dim theText as String
theText = iString 'Set the string to whatever you plan to search
If InStrB(LCase$(theText), "gloss:") then 'Check to make sure it is there
line1Case1 = Mid$(theText, 10, InStr(theText, "+")) 'Gets the first item in the first line
theText = Mid$(theText, Len(Line1Case1) + 1)
line1Case2 = Mid$(theText, 1, InStr(theText, "+")) 'Gets the second item in the first line
'Repeat for the rest of the items
End If
Something like that would work. However, if all you need is to get the items between the last two plus signs, it would be much more simple to use something like InStrRev.
Re: help to chang my code....please
You did this; gloss = Split(tmp(x + 1), "+")
So check If Ubound(gloss) >=2, this indicates a line with more than two +
If there are more than two +, then simply access element gloss(Ubound(gloss) - 1)). This element is the one nested between last two plus signs.
Re: help to chang my code....please
i tried whAt westconn1 wrote
it was what i'm looking for
thanks everyone for your help