|
-
Dec 16th, 2004, 02:25 PM
#1
Thread Starter
Addicted Member
A function to get the specific part of a text
I hope it will be useful to someone somehow(i found it practical). It gets the specific part in a text between the begining and the ending strings;
VB Code:
'In a module type the following:
Function Between(Begining As String, Ending As String, TextToLookIn As String)
Dim Be As String, En As String, TTLI As String
Be = Begining
En = Ending
TTLI = TextToLookIn
TTLI = Right(TTLI, Len(TTLI) - (InStr(1, TTLI, Be) + Len(Be) - 1))
TTLI = Left(TTLI, InStr(1, TTLI, En) - 1)
Between = TTLI
End Function
Hope it will be useful. If u think its not useful plz pm me.
Last edited by kill_bill_gates; Dec 21st, 2004 at 02:39 PM.
"Quis custodiet ipsos custodes?"
Juvenal
Mete the Hun wanted to live in peace with the Chinese. So he gave the Chinese Emperor his favorite horse, best swords in his armory, and lots of other cool stuff. But then the Chinese Emperor asked for one thing. A useless land through the north. It was a small, useless, unproductive, uninhabited piece of land. But Mete the Hun's answer was certain:
I gave you horses, weapons and much more which belonged to me. But the lands are not mine, it's my nation's and I'm ready to fight, kill and die for just an inch my country
-=Joey Jordison R0CKS!! =-
-
Dec 16th, 2004, 11:41 PM
#2
New Member
Re: A function to get the specific part of a text
Be = Begining
En = Ending
TTLI = TextToLookIn
you could use the parameter vars directly
makes your routine more tight!!!!!
aRCHITEKTON of Programming Thought and LITERATURe
-
Dec 19th, 2004, 06:19 PM
#3
Re: A function to get the specific part of a text
If you used Option Explicit you wouldn't have any spelling mistakes. Also when you define things like this
Dim Be, En, TTLI As String
only TTLI gets defines as a string. The others default to Variants which are slower and larger than any other variables.
-
Dec 19th, 2004, 06:48 PM
#4
Re: A function to get the specific part of a text
The GLOBAL variable has to go away.
The function should return a string variable.
Having a GLOBAL variable breaks the black-box rules - doesn't fit ACID concept.
No reason to move BEGINING and END into other variables - that is a huge waste of time.
Also, find the start and end position of the string with INSTR and do the math to store those positions - in longword variables.
Cut the string up only once.
Moving and cutting the string three times would not be acceptable in our shop.
We develop programs that process sometimes thousand and thousands of records from a database - being tight and clean is important in the long run.
-
Dec 21st, 2004, 02:26 PM
#5
Thread Starter
Addicted Member
Re: A function to get the specific part of a text
And this code is to use in a "module "... If u dont use GLOBAL the thing wont work in the rest of the program....
"Quis custodiet ipsos custodes?"
Juvenal
Mete the Hun wanted to live in peace with the Chinese. So he gave the Chinese Emperor his favorite horse, best swords in his armory, and lots of other cool stuff. But then the Chinese Emperor asked for one thing. A useless land through the north. It was a small, useless, unproductive, uninhabited piece of land. But Mete the Hun's answer was certain:
I gave you horses, weapons and much more which belonged to me. But the lands are not mine, it's my nation's and I'm ready to fight, kill and die for just an inch my country
-=Joey Jordison R0CKS!! =-
-
Dec 21st, 2004, 02:30 PM
#6
Re: A function to get the specific part of a text
Why must you use a GLOBAL variable instead of having the FUNCTION return the string?
Standard function practice would be:
Code:
Function Between(Begining As String, Ending As String, TextToLookIn As String) As String
.
.
.
Between=TTLI
End Function
-
Dec 21st, 2004, 02:32 PM
#7
Thread Starter
Addicted Member
Re: A function to get the specific part of a text
ok, thats good but the program i was working on when i wrote this had to be like that... But the one u said is better for general purposes.
"Quis custodiet ipsos custodes?"
Juvenal
Mete the Hun wanted to live in peace with the Chinese. So he gave the Chinese Emperor his favorite horse, best swords in his armory, and lots of other cool stuff. But then the Chinese Emperor asked for one thing. A useless land through the north. It was a small, useless, unproductive, uninhabited piece of land. But Mete the Hun's answer was certain:
I gave you horses, weapons and much more which belonged to me. But the lands are not mine, it's my nation's and I'm ready to fight, kill and die for just an inch my country
-=Joey Jordison R0CKS!! =-
-
Jan 5th, 2005, 03:50 PM
#8
Junior Member
Re: A function to get the specific part of a text
Ok i am making a money tree grabber. Refer to this post for more info:http://www.vbforums.com/showthread.p...62#post1879362
If I want to grab the ID of items in a page source...how would i do that?
"It is a hard thing to fall, it is even harder to admit to that fall."
-Darth Treya
Star Wars: Knights of the Old Republic II
-
May 8th, 2005, 09:18 AM
#9
Thread Starter
Addicted Member
Re: A function to get the specific part of a text
Hey, I've made it better(i guess);
VB Code:
Function Between(TextToLookIn As String, Begining As String, Ending As String)
Between = Left(Right(TextToLookIn, Len(TextToLookIn) - InStr(1, TextToLookIn, Begining) - Len(Begining) + 1), InStr(1, Right(TextToLookIn, Len(TextToLookIn) - InStr(1, TextToLookIn, Begining) - Len(Begining)), Ending))
End Function
"Quis custodiet ipsos custodes?"
Juvenal
Mete the Hun wanted to live in peace with the Chinese. So he gave the Chinese Emperor his favorite horse, best swords in his armory, and lots of other cool stuff. But then the Chinese Emperor asked for one thing. A useless land through the north. It was a small, useless, unproductive, uninhabited piece of land. But Mete the Hun's answer was certain:
I gave you horses, weapons and much more which belonged to me. But the lands are not mine, it's my nation's and I'm ready to fight, kill and die for just an inch my country
-=Joey Jordison R0CKS!! =-
-
May 11th, 2005, 01:27 PM
#10
Re: A function to get the specific part of a text
The functions I posted in this thread are just as usefull, the function LeftRange does the same thing as what yours does...
VB - Some functions that makes string parsing easier
You have to copy and paste the code into a module...
-
May 19th, 2005, 08:59 AM
#11
Banned
Re: A function to get the specific part of a text
kill_bill_gates, if you want to kill Bill Gates whytf do you use his software?
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
|