SRL Archive - FAQ

[STRING].Contains("") in SIMBA?


Jethr0x

2010-07-30 14:53:51

How can you check if s1 is in s2?

Example:

String: Hello, how are you?

How do you see if the word "are" is located in the string?

Here is my code, commented out is how you would do it in C…

program PhotobucketAlbumChecker;

const
URL = 'http://s198.photobucket.com/albums/aa286/hellabawm/';

var
albums : TStringArray;

procedure TryAlbum(L : string);
var
str : string;
begin
str := GetPage(L);
str := Between('<title>', '</title>', str);
Writeln(str);
// if str.Contains("Private") {
// Writeln('Private Album: ' + L);
// } else if (str.Contains("Pictures by ") {
// Writeln('Public Album: ' + L);
// }
end;

procedure CheckAlbums(URL: string);
var
i : integer;
link : string;
begin
albums := ['', 'new', 'New', 'NeW', 'NEW']
for i := 0 to (GetArrayLength(albums) - 1) do
begin
link := URL + albums[i];
Writeln('Trying: ' + link);
TryAlbum(link);
end;
end;


begin
ClearDebug;
CheckAlbums(URL);
end.

Blumblebee

2010-07-30 15:13:55

I think your looking for pos()

MasterKill

2010-07-30 16:45:45


if(pos('hello', 'the world says hello!') > 0)then
WriteLn('Found in the string!')
else
WriteLn('Not Found!');

(omg no simba tags!)

NCDS

2010-07-30 16:49:37


{*******************************************************************************
function InStrArrEx(S: Sstring; StrArr: TStringArray; var Where: Integer): Boolean;
By: n3ss3s
Description: Returns true if the string S was found in the StrArr, and if so
stores the index into Where.
*******************************************************************************}
function InStrArrEx(S: string; StrArr: TStringArray; var Where: Integer): Boolean;
var
I, H: Integer;
begin
H := High(StrArr);
for I := 0 to H do
if LowerCase(StrArr[i]) = LowerCase(S) then
begin
Where := i;
Result := True;
Break;
end;
end;

{*******************************************************************************
function StrInArr(str: string; arrS: TStringArray): Boolean;
By: Narcle & Nava2
Description: Returns True if str is found in the Array. Case sensitive. Uses Pos
*******************************************************************************}
function StrInArr(str: string; arrS: TStringArray): Boolean;
var
I, L, H: Integer;
begin
Result := True;
L := Low(arrS); H := High(arrS);
for I := L to H do
if Pos(Str, arrS[I]) > 0 then
Exit;
Result := False;
end;

{*******************************************************************************
function ArrInStr(arrS: TStringArray; str: string): Boolean;
By: Narcle & Nava2
Description: Returns True if the Array is found in the str. Case sensitive. Uses Pos
*******************************************************************************}
function ArrInStr(arrS: TStringArray; str: string): Boolean;
var
I, L, H: Integer;
begin
Result := True;
L := Low(arrS); H := High(arrS);
for I := L to H do
if Pos(arrS[I], Str) > 0 then
Exit;
Result := False;
end;
Text.Simba in SRL ;) you may find them useful.

Jethr0x

2010-07-30 17:15:42

Well, im using pos(), thanks bumblebee!