SRL Archive - SRL Archives

TextBetw() - Check if the text is in between Betw and Betw.


Ron

2007-01-26 17:27:46

// Checks if the Text in TheStr is in between Betw and Betw.
// If CheckIn is true, then check if the Text is between Betw and Betw. If
// so, then result in the position. If not, then check if it's outside. If
// so, result in -1. If not, then result in -2.
// if CheckIn is false, then check if the Text is outside of Betw and Betw.
// If so, then result in -1, if not, then result in -2.
// Made by Ron :)

function code:

// Checks if the Text in TheStr is in between Betw and Betw.
// If CheckIn is true, then check if the Text is between Betw and Betw. If
// so, then result in the position. If not, then check if it's outside. If
// so, result in -1. If not, then result in -2.
// if CheckIn is false, then check if the Text is outside of Betw and Betw.
// If so, then result in -1, if not, then result in -2.
// Made by Ron :)
function TextBetw(TheStr, Text, Betw : string; CheckIn : boolean) : integer;
var
i : integer;
begin
if(CheckIn)then
begin
i := Pos(Text, Between(Betw,Betw,TheStr));
if(i = 0)and(pos(Text,TheStr) > 0)then
Result := -1
else if(i = 0)then
Result := -2
else
Result := i;
end else
begin
delete(TheStr,pos(Betw, TheStr),pos(Betw, TheStr)+Length(Between(Betw,Betw,TheStr)));
if(pos(Text,TheStr) > 0)then
Result := -1
else
Result := -2;
end;
end;

Test function code:

program TestTextBetw;

const
// The main string to look for the text.
TheStr = 'Edit1.Text := ''Edit1.Text - Type your username in here'';';
// What to check for.
Text = 'Edit1';
// Check the text between what?
Betw = ''''; // The 2 single quotes symbolize 1 single quote.

// Checks if the Text in TheStr is in between Betw and Betw.
// If CheckIn is true, then check if the Text is between Betw and Betw. If
// so, then result in the position. If not, then check if it's outside. If
// so, result in -1. If not, then result in -2.
// if CheckIn is false, then check if the Text is outside of Betw and Betw.
// If so, then result in -1, if not, then result in -2.
// Made by Ron :)
function TextBetw(TheStr, Text, Betw : string; CheckIn : boolean) : integer;
var
i : integer;
begin
if(CheckIn)then
begin
i := Pos(Text, Between(Betw,Betw,TheStr));
if(i = 0)and(pos(Text,TheStr) > 0)then
Result := -1
else if(i = 0)then
Result := -2
else
Result := i;
end else
begin
delete(TheStr,pos(Betw, TheStr),pos(Betw, TheStr)+Length(Between(Betw,Betw,TheStr)));
if(pos(Text,TheStr) > 0)then
Result := -1
else
Result := -2;
end;
end;

begin
ClearDebug;
if(TextBetw(TheStr, Text, Betw, True) > 0)then
WriteLn('The text is inside the '+Betw+' and '+Betw+'!')
else if(TextBetw(TheStr, Text, Betw, True) = -1)then
WriteLn('The text is in the str, but not inside the '+Betw+' and '+Betw+'!')
else if(TextBetw(TheStr, Text, Betw, True) = -2)then
WriteLn('The text is not in the string!');

if(TextBetw(TheStr, Text, Betw, False) = -1)then
WriteLn('The text is outside!')
else if(TextBetw(TheStr, Text, Betw, False) = -2)then
WriteLn('The text is not outside!');
end.

How is this useful? Well, who knows. It's useful to me, cause this is how I check important information in DFM files to make sure what I'm looking for is outside of single quotes. Hope you find it useful.

~Ron :)

Wizzup?

2007-01-27 02:57:11

function Between(s1, s2, s: string): string; - returns part of string s between substrings s1 and s2. 

But nice job.

Between(s1, s2, s)
If S = '' Then TerminateScript;

Ron

2007-01-27 14:16:55

Edit: Wizzup, yesterday, I didn't read your example at all. Sorry.

I realized though, what you posted above is not even close to what my function can do. Did you read my explanation at all?

The TextBetw function can tell you if the text is in between the Betw's, outside of the Betw's, or not in the string at all.

Your script just ends the script when nothing is found in between s1, and s2. And yes I was very aware of that function, and for a long time too. I don't think you understood the function. Look over when you can, I just updated cause I found a small bug and several ways to improve it.

Make sure to look at the test function code, to see how you can check if the text is outside/inside the betw's.

almost

2008-03-30 20:50:49

I made a function pretty much the same as this and found it useful for editing HTML.
I would make it look between <title> and </title> to find the title of a page, then change it to something else.
Then it shows up on history and stuff as whatever you changed it to.

Bobarkinator

2008-03-30 22:59:31

Don't go around gravedigging please.

Freddy1990

2008-03-31 06:18:00

Wow, nice bump, almost, you deserve the "One year+ bump almost got me banned" award :p

Markus

2008-03-31 15:40:00

Hmm, is this a record?

MylesMadness

2008-03-31 20:55:03

it just might be

almost

2008-04-01 00:11:26

Lol sorry guys i thought that at the bottom where it shows "related posts", they would be new posts.
Otherwise, why is that even there?
But aren't all… like 5 people that just posted after me doing the same thing, for some strange reason?

Wow, nice bump, almost, you deserve the "One year+ bump almost got me banned" award

Can you seriously get banned for a silly mistake?

Freddy1990

2008-04-03 07:31:34

From: almost
Lol sorry guys i thought that at the bottom where it shows "related posts", they would be new posts.
Otherwise, why is that even there?
But aren't all… like 5 people that just posted after me doing the same thing, for some strange reason?


Can you seriously get banned for a silly mistake?

Nah, unless maybe you make it a habbit :p