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:
Test function code:
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 :)
// 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 :)