SRL Archive - OSR Help

Storing variables in a TPA/TSA without setting array length?


Xtensity

2010-06-09 22:31:07

Is this possible? I tried to do it and got run time errors, which to fix I had to over-complicate my script.

Why can't an undefined TPA/TSA automatically have a length of 0, then any variable that is added into the array, the length would automatically increases.

Any tips/clues?

Awkwardsaw

2010-06-09 22:33:39

post script, it shouldnt be too complicated :)

Xtensity

2010-06-09 22:49:31

It's a function.

I made it so it looks at a string(made it to look at web page source codes), and it gets all items that appear between a certain 2 strings or something.

Meaning

if I have a page like this
[T]A[/T]
[T]B[/T]
[T]C[/T]
[T]D[/T]
[T]E[/T]
[T]F[/T]
[T]G[/T]

I can make it store in a TStringArray each varible/text that is between [T] and [/T], or whatever I specify.


All the comments in this script were for my own use, so don't worry if you don't understand them. Good luck understanding the script as it is. There's also a ton of unused variables in the top that I used when putting the scripts basic function together.


The function does work.


function GetAllBetween(OS,f1,f2:String):TStringArray;
var
x,y,z,FirstP,FileN,FileLength:integer;
s,FIS,f3,NS:String;
TS2:TStringArray;
begin
NS:=OS
//-----------------
f3:=Between(f1,f2,NS)//Gets Whatever is inbetween
while Length(f3) > 0 do
begin
Y:=Y+1
f3:=Between(f1,f2,NS)//Gets Whatever is inbetween
NS:=replace(NS,f1+f3+f2,'')//Removes whatever was inbetween
f3:=Between(f1,f2,NS)//Gets Whatever is inbetween
end;
//-----------------
//-----------------
NS:=OS
//writeln(Y)
SetArrayLength(TS2,Y)
f3:=Between(f1,f2,NS)//Gets Whatever is inbetween
//writeln(f2)
for z:=0 to high(TS2) do
begin
TS2[Z]:=f3
f3:=Between(f1,f2,NS)//Gets Whatever is inbetween
NS:=replace(NS,f1+f3+f2,'')//Removes whatever was inbetween
f3:=Between(f1,f2,NS)//Gets Whatever is inbetween
end;
//-----------------
result:=TS2;
end;

Awkwardsaw

2010-06-09 22:52:23

use explode(). :)

Xtensity

2010-06-09 22:55:40

From: Awkwardsaw
use explode(). :)


er


It has to get the text between whatever I specify first. I am aware of explode(), but I am not sure how it fits into what I am trying to do/did.

Mainly because this function was made with the intention of looking at a WebPage source code, and pulling certain bits of information from between specified html code.

Awkwardsaw

2010-06-09 23:01:22

From: Xtensity
er


It has to get the text between whatever I specify first. I am aware of explode(), but I am not sure how it fits into what I am trying to do/did.

Mainly because this function was made with the intention of looking at a WebPage source code, and pulling certain bits of information from between html code.



program new;

function GetAllBetween(OS,f1,f2:String):TStringArray;
var
s : String;
i : integer;
begin
result := explode(f1, OS);
for i := 0 to high(result) do
s := s + result[i];
result := explode(f2, s);
end;

var
arr : String;
begin
arr := '[T]A[/T][T]B[/T][T]C[/T][T]D[/T][T]E[/T][T]F[/T][T]G[/T]'
writeln(GetAllBetween(arr, '[T]','[/T]'));
end.

something to this affect? :)

Xtensity

2010-06-09 23:11:08

From: Awkwardsaw

program new;

function GetAllBetween(OS,f1,f2:String):TStringArray;
var
s : String;
i : integer;
begin
result := explode(f1, OS);
for i := 0 to high(result) do
s := s + result[i];
result := explode(f2, s);
end;

var
arr : String;
begin
arr := '[T]A[/T][T]B[/T][T]C[/T][T]D[/T][T]E[/T][T]F[/T][T]G[/T]'
writeln(GetAllBetween(arr, '[T]','[/T]'));
end.

something to this affect? :)


Interesting, didn't know explode worked in that manner. I'm going to experiment with this a little more to better understand explode.

Thanks :P

Edit:It works in that instance, but does not work in how I designed it to, with webpages… I will explain in a sec

Awkwardsaw

2010-06-09 23:13:47

From: Xtensity
Interesting, didn't know explode worked in that manner. I'm going to experiment with this a little more to better understand explode.

Thanks :P


it's actually pretty crude, but all it does is remove a part of the tag from the string, then it turns the TSA into a string, then i do an other explode again for the last part of the tag, if that makes any sence :)

Xtensity

2010-06-09 23:16:16

I took your script and applied it to how I designed my other script, and it did not work correctly..

Here's the script with the variables I changed.

program new;

function GetAllBetween(OS,f1,f2:String):TStringArray;
var
s : String;
i : integer;
begin
result := explode(f1, OS);

for i := 0 to high(result) do
begin
writeln(result[i])
s := s + result[i];
end;
result := explode(f2, s);
end;

var
x: integer;
arr : String;
TS:TSTringArray;
begin
arr:=GetPage('http://www.reverbnation.com/page_object/page_object_fans/artist_3451?fans_page=1')
TS:=GetAllBetween(arr, '<div class="po_name"><a href="','">')
for x:=0 to high(TS) do
writeln(TS[x]);
end.

My version of the function would have retrieved:
/harmonyflo
/fan/tonymecham1
/figidyphantum
/elianamarcia
/finboy
/mijo1810
/fan/dagreatone
/micvandalakaghost
/zikhan
/djm1ked33
/socraze
/fan/amy126592
/theflygentlemen
/pennyjayneblack
/label/northwestmusicscene
/newwestent
/saneatx01
/djchixdigmoney
/sleepybeeandthestingers
/rapidtraxx1




Your version retrieved………. well run the script above and see for yourself.

Awkwardsaw

2010-06-09 23:21:12

that's because my version only works with the exact situation as you posted above, :p

for this you need a different string manipulation.. read up on loops, delete(), and pos(). ;)

naum has an awesome string tutorial, you just need your imagination :)

Xtensity

2010-06-09 23:25:30

From: Awkwardsaw
that's because my version only works with the exact situation as you posted above, :p

for this you need a different string manipulation.. read up on loops, delete(), and pos(). ;)

naum has an awesome string tutorial, you just need your imagination :)



I know, i got my original function working.. That wasn't the point of this post lol. I basically want to count The amount of times <div class="po_name"><a href="*********"> appears, with the stars representing wild cards. I spent about 2 days trying to figure out how to, if there is, wild cards in scar. Since the data in between those 2 strings varries, and I cant just make it count the occurrence of one of those strings because it has to be that specific combination.


I'm not even sure if there is a function to count the occurance of a string within a string.

Awkwardsaw

2010-06-09 23:27:46

From: Xtensity
I know, i got my original function working.. That wasn't the point of this post lol. I basically want to count The amount of times <div class="po_name"><a href="*********"> appears, with the stars representing wild cars. I spent about 2 days trying to figure out how to, if there is, wild cards in scar. Since the data in between those 2 strings varries, and I cant just make it count the occurrence of one of those strings because it has to be that specific combination.


exactly, :) use a loop, delete() and pos(). once you find one instance, get the position of the last character in the thing(>) delete every thing that is before it, and start over, increasing (x, or c or w/e) by one

Xtensity

2010-06-09 23:30:53

From: Awkwardsaw
exactly, :) use a loop, delete() and pos(). once you find one instance, get the position of the last character in the thing(>) delete every thing that is before it, and start over, increasing (x, or c or w/e) by one


That's exactly what I did in my original script :P. I had to do that to find out how many times the things occured. After each one is found, it's replaced with nothing, and an integer variable is increased. After that loop, it sets the length of the array, and repeats the loop, but this second time it repeats the loop it stores each found name within the array.

Awkwardsaw

2010-06-09 23:34:19

From: Xtensity
That's exactly what I did in my original script :P. I had to do that to find out how many times the things occured. After each one is found, it's replaced with nothing, and an integer variable is increased. After that loop, it sets the length of the array, and repeats the loop, but this second time it repeats the loop it stores each found name within the array.


oh, for some reason i didnt see that :<

anyways, that's the only way i can think of how to do it, unless the regex functions somehow help, but i doubt it :p