sjesper Posted April 21, 2012 Share Posted April 21, 2012 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 :-) Quote Link to comment Share on other sites More sharing options...
FHannes Posted April 21, 2012 Share Posted April 21, 2012 Tbh, I really don't understand the question... Quote Link to comment Share on other sites More sharing options...
sjesper Posted April 21, 2012 Author Share Posted April 21, 2012 Wow i failed in the post. I ofc ment Between(String; String; TStringArray) Quote Link to comment Share on other sites More sharing options...
Janilabo Posted April 21, 2012 Share Posted April 21, 2012 (edited) 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 April 21, 2012 by Janilabo Fixes, fixes! Quote Link to comment Share on other sites More sharing options...
sjesper Posted April 21, 2012 Author Share Posted April 21, 2012 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 If someone wants it pm me xP) Quote Link to comment Share on other sites More sharing options...
Janilabo Posted April 21, 2012 Share Posted April 21, 2012 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.. (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? Quote Link to comment Share on other sites More sharing options...
sjesper Posted April 21, 2012 Author Share Posted April 21, 2012 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.. (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 Just saw ur library :-) If you havn't then should you might consider adding this method to it 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 ^^ Quote Link to comment Share on other sites More sharing options...
LordJashin Posted April 22, 2012 Share Posted April 22, 2012 We should start adding stuff like this to OSI. Even if they don't deserve a place somewhere. Could put them in a scar file called random or other. Then whenever in need just go look in OSI for it first. If its not there, make it, and if it's logical it could be added to OSI. Quote Link to comment Share on other sites More sharing options...
Janilabo Posted April 22, 2012 Share Posted April 22, 2012 @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. 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. 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". -Jani Quote Link to comment Share on other sites More sharing options...