Jump to content
sjesper

Trim"S"

Recommended Posts

Hello.

 

Is there any function to scan a whole string and get all the matching in a TStringArray using the method Trim?

 

In other words: a Trims(String; String; TStringArray).

 

---------- Post added at 08:29 PM ---------- Previous post was at 08:11 PM ----------

 

Well doesn't matter, i just ran a for loop and deleted the string after it was used so it would go to another string :-)

Link to comment
Share on other sites

Hello sjesper,

 

I wrote this to you:

 

[scar]function TSAAllBetween(s1, s2: string; TSA: TStringArray): TStringArray;

var

start, finish, h, i, l, r, s1L: Integer;

s: string;

begin

h := High(TSA);

if h < 0 then

Exit;

s1L := Length(s1);

SetLength(Result, (h + 1));

for i := 0 to h do

begin

s := TSA;

l := Length(s);

if l > 1 then

begin

start := Pos(s1, s);

if (start > 0) and (start <= (l - 1)) then

begin

finish := LastPos(s2, s);

if finish > ((start + s1L) - 1) then

begin

Result[r] := Copy(s, (start + s1L), (finish - (start + s1L)));

Inc®;

end;

end;

end;

s := '';

end;

SetLength(Result, r);

end;

 

var

tmp, TSA: TStringArray;

tm, h, i: Integer;

 

begin

ClearDebug;

tmp := ['[Test1]', '[Test2]', '[Test?*', '[Test3]', '!Test?]',

'[Test4]', '[Test5]', 'Test?', '|Test?|', '[Test6]'];

tm := GetSystemTime;

TSA := TSAAllBetween('[', ']', tmp);

WriteLn('TSAAllBetween handled "tmp" in just ' + IntToStr(GetSystemTime - tm) + ' ms.');

SetLength(tmp, 0);

h := High(TSA);

for i := 0 to h do

WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA);

SetLength(TSA, 0);

end.[/scar]

 

Is it what you are looking for? :)

 

You can use the same brackets for it aswell, like this:

 

[scar]function TSAAllBetween(s1, s2: string; TSA: TStringArray): TStringArray;

var

start, finish, h, i, l, r, s1L: Integer;

s: string;

begin

h := High(TSA);

if h < 0 then

Exit;

s1L := Length(s1);

SetLength(Result, (h + 1));

for i := 0 to h do

begin

s := TSA;

l := Length(s);

if l > 1 then

begin

start := Pos(s1, s);

if (start > 0) and (start <= (l - 1)) then

begin

finish := LastPos(s2, s);

if finish > ((start + s1L) - 1) then

begin

Result[r] := Copy(s, (start + s1L), (finish - (start + s1L)));

Inc®;

end;

end;

end;

s := '';

end;

SetLength(Result, r);

end;

 

var

tmp, TSA: TStringArray;

tm, h, i: Integer;

 

begin

ClearDebug;

tmp := ['||||', '|||||', '||||||', '|||||||', '||||||||', '|||||||||', '||||||||||'];

tm := GetSystemTime;

TSA := TSAAllBetween('||', '||', tmp);

WriteLn('TSAAllBetween handled "tmp" in just ' + IntToStr(GetSystemTime - tm) + ' ms.');

SetLength(tmp, 0);

h := High(TSA);

for i := 0 to h do

WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA);

SetLength(TSA, 0);

end.[/scar]

Edited by Janilabo
Fixes, fixes!
Link to comment
Share on other sites

Hello sjesper,

 

I wrote this to you:

 

[scar]function TSAAllBetween(s1, s2: string; TSA: TStringArray): TStringArray;

var

start, finish, h, i, l, r, s1L: Integer;

s: string;

begin

h := High(TSA);

if h < 0 then

Exit;

s1L := Length(s1);

SetLength(Result, (h + 1));

for i := 0 to h do

begin

s := TSA;

l := Length(s);

if l > 1 then

begin

start := Pos(s1, s);

if (start > 0) and (start <= (l - 1)) then

begin

finish := LastPos(s2, s);

if finish > ((start + s1L) - 1) then

begin

Result[r] := Copy(s, (start + s1L), (finish - (start + s1L)));

Inc®;

end;

end;

end;

s := '';

end;

SetLength(Result, r);

end;

 

var

tmp, TSA: TStringArray;

tm, h, i: Integer;

 

begin

ClearDebug;

tmp := ['[Test1]', '[Test2]', '[Test?*', '[Test3]', '!Test?]',

'[Test4]', '[Test5]', 'Test?', '|Test?|', '[Test6]'];

tm := GetSystemTime;

TSA := TSAAllBetween('[', ']', tmp);

WriteLn('TSAAllBetween handled "tmp" in just ' + IntToStr(GetSystemTime - tm) + ' ms.');

SetLength(tmp, 0);

h := High(TSA);

for i := 0 to h do

WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA);

SetLength(TSA, 0);

end.[/scar]

 

Is it what you are looking for? :)

 

You can use the same brackets for it aswell, like this:

 

[scar]function TSAAllBetween(s1, s2: string; TSA: TStringArray): TStringArray;

var

start, finish, h, i, l, r, s1L: Integer;

s: string;

begin

h := High(TSA);

if h < 0 then

Exit;

s1L := Length(s1);

SetLength(Result, (h + 1));

for i := 0 to h do

begin

s := TSA;

l := Length(s);

if l > 1 then

begin

start := Pos(s1, s);

if (start > 0) and (start <= (l - 1)) then

begin

finish := LastPos(s2, s);

if finish > ((start + s1L) - 1) then

begin

Result[r] := Copy(s, (start + s1L), (finish - (start + s1L)));

Inc®;

end;

end;

end;

s := '';

end;

SetLength(Result, r);

end;

 

var

tmp, TSA: TStringArray;

tm, h, i: Integer;

 

begin

ClearDebug;

tmp := ['||||', '|||||', '||||||', '|||||||', '||||||||', '|||||||||', '||||||||||'];

tm := GetSystemTime;

TSA := TSAAllBetween('||', '||', tmp);

WriteLn('TSAAllBetween handled "tmp" in just ' + IntToStr(GetSystemTime - tm) + ' ms.');

SetLength(tmp, 0);

h := High(TSA);

for i := 0 to h do

WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA);

SetLength(TSA, 0);

end.[/scar]

 

Yes it is, even thought i found another method to do it that was only 2 lines ^^ (Btw im leeching minecraft accounts of the mc forum and it's working now :D If someone wants it pm me xP)

Link to comment
Share on other sites

Added some more fixes to my function, to prevent incorrect results:

 

[scar]function TSAAllBetween(s1, s2: string; TSA: TStringArray): TStringArray;

var

start, finish, h, i, l, r, s1L, s2L: Integer;

s: string;

begin

h := High(TSA);

if h < 0 then

Exit;

s1L := Length(s1);

s2L := Length(s2);

SetLength(Result, (h + 1));

for i := 0 to h do

begin

s := TSA;

l := Length(s);

if l > ((s1L + s2L) - 1) then

begin

start := Pos(s1, s);

if (start > 0) then

if (((start + s1L) - 1) < ((l - s2L) + 1)) then

begin

finish := LastPos(s2, s);

if finish > ((start + s1L) - 1) then

begin

Result[r] := Copy(s, (start + s1L), (finish - (start + s1L)));

Inc®;

end;

end;

end;

s := '';

end;

SetLength(Result, r);

end;[/scar]

 

Alrightys sjesper, can you show your method, that you are using right now? I would love to see it.. :P (Just to see if it does indeed work correctly, with same brackets)

 

Test it with this:

 

[scar]function TSAAllBetween(s1, s2: string; TSA: TStringArray): TStringArray;

var

start, finish, h, i, l, r, s1L, s2L: Integer;

s: string;

begin

h := High(TSA);

if h < 0 then

Exit;

s1L := Length(s1);

s2L := Length(s2);

SetLength(Result, (h + 1));

for i := 0 to h do

begin

s := TSA;

l := Length(s);

if l > ((s1L + s2L) - 1) then

begin

start := Pos(s1, s);

if (start > 0) then

if (((start + s1L) - 1) < ((l - s2L) + 1)) then

begin

finish := LastPos(s2, s);

if finish > ((start + s1L) - 1) then

begin

Result[r] := Copy(s, (start + s1L), (finish - (start + s1L)));

Inc®;

end;

end;

end;

s := '';

end;

SetLength(Result, r);

end;

 

var

tmp, TSA: TStringArray;

tm, h, i: Integer;

 

begin

ClearDebug;

tmp := ['||||', '|||||', '||||||', '|||||||', '||||||||', '|||||||||', '||||||||||'];

tm := GetSystemTime;

TSA := TSAAllBetween('||', '||', tmp);

WriteLn('TSAAllBetween handled "tmp" in just ' + IntToStr(GetSystemTime - tm) + ' ms.');

SetLength(tmp, 0);

h := High(TSA);

for i := 0 to h do

WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA);

SetLength(TSA, 0);

end.[/scar]

 

..and see if the results are same for both methods? :)

Link to comment
Share on other sites

Added some more fixes to my function, to prevent incorrect results:

 

[scar]function TSAAllBetween(s1, s2: string; TSA: TStringArray): TStringArray;

var

start, finish, h, i, l, r, s1L, s2L: Integer;

s: string;

begin

h := High(TSA);

if h < 0 then

Exit;

s1L := Length(s1);

s2L := Length(s2);

SetLength(Result, (h + 1));

for i := 0 to h do

begin

s := TSA;

l := Length(s);

if l > ((s1L + s2L) - 1) then

begin

start := Pos(s1, s);

if (start > 0) then

if (((start + s1L) - 1) < ((l - s2L) + 1)) then

begin

finish := LastPos(s2, s);

if finish > ((start + s1L) - 1) then

begin

Result[r] := Copy(s, (start + s1L), (finish - (start + s1L)));

Inc®;

end;

end;

end;

s := '';

end;

SetLength(Result, r);

end;[/scar]

 

Alrightys sjesper, can you show your method, that you are using right now? I would love to see it.. :P (Just to see if it does indeed work correctly, with same brackets)

 

Test it with this:

 

[scar]function TSAAllBetween(s1, s2: string; TSA: TStringArray): TStringArray;

var

start, finish, h, i, l, r, s1L, s2L: Integer;

s: string;

begin

h := High(TSA);

if h < 0 then

Exit;

s1L := Length(s1);

s2L := Length(s2);

SetLength(Result, (h + 1));

for i := 0 to h do

begin

s := TSA;

l := Length(s);

if l > ((s1L + s2L) - 1) then

begin

start := Pos(s1, s);

if (start > 0) then

if (((start + s1L) - 1) < ((l - s2L) + 1)) then

begin

finish := LastPos(s2, s);

if finish > ((start + s1L) - 1) then

begin

Result[r] := Copy(s, (start + s1L), (finish - (start + s1L)));

Inc®;

end;

end;

end;

s := '';

end;

SetLength(Result, r);

end;

 

var

tmp, TSA: TStringArray;

tm, h, i: Integer;

 

begin

ClearDebug;

tmp := ['||||', '|||||', '||||||', '|||||||', '||||||||', '|||||||||', '||||||||||'];

tm := GetSystemTime;

TSA := TSAAllBetween('||', '||', tmp);

WriteLn('TSAAllBetween handled "tmp" in just ' + IntToStr(GetSystemTime - tm) + ' ms.');

SetLength(tmp, 0);

h := High(TSA);

for i := 0 to h do

WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA);

SetLength(TSA, 0);

end.[/scar]

 

..and see if the results are same for both methods? :)

 

Wow ur talented dude :o Just saw ur library :-) If you havn't then should you might consider adding this method to it :P

 

My method wasn't really a method, but it working in the way i needed it :-)

 

I just GetPage the whole thing and then used the between command for getting the username in a for loop and then delete the username so it would go to the next one next time.

 

I don't know if u understood it. I just dont want to make this code public as i'm not sure the script is legal ^^

Link to comment
Share on other sites

@sjesper: Thanks mate.

..and don't worry about not releasing script, I do understand, that there is a good reason why you cannot release it to public. :P

I am happy you got your script working! So this problem is solved here.. :)

 

@LordJashin: Yeah, but, we aren't really allowed to decide what can/will be added to OSI.

Because after all, it's still Wanted's project here (and he is doing a really good job with it! I am not complaining at all, I actually appreciate hes work with OSI). He is the man in charge of OSI.

 

We can always request/suggest stuff that could be added there, of course.

Wont do any harm. :P

 

I must say, I am happy about the way things currently work around SCAR-Divi community, though.

..like, multiple include projects are highly appreciated here, whereas, at SRL-forums things run mostly around the SRL include only, and any alternative includes wont get too much attention there... If any attention at all.

 

It's better like this, trust me!

This way there is some friendly "competition". :D

 

-Jani

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...