|
-
Oct 12th, 2006, 03:53 PM
#1
Thread Starter
Addicted Member
[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
Last edited by om-yousif; Oct 12th, 2006 at 03:56 PM.
-
Oct 12th, 2006, 05:43 PM
#2
Re: help to chang my code....please
maybe this will work for you
VB Code:
sLine = sLine & " (" & Trim(gloss(UBound(gloss) - 1)) & ");"
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 13th, 2006, 06:36 AM
#3
Hyperactive Member
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.
-
Oct 13th, 2006, 06:50 AM
#4
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.
-
Oct 13th, 2006, 02:56 PM
#5
Thread Starter
Addicted Member
Re: help to chang my code....please
i tried whAt westconn1 wrote
it was what i'm looking for
thanks everyone for your help
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
|