Sorry if you feel cheated, but no explosions in this thread. Aww what the hell. Have one. http://sightsonics.cf.huffingtonpost...-explosion.jpg
Anyway, that stupidity out of the way![]()
I got bored and made a function, explode. If you've ever used PHP, Perl, or the Java equivalent, Split(), then you know what it is. If not, it takes a string and splits it into an array, based on a common delimiter.
ex: "Cheese+Is+Tasty" Would become Arr[0] := 'Cheese', Arr[1] := 'Is' Arr[3] := 'Tasty'
To be honest, I can't even think where it would be useful, but...what the hay. I made it anyway. Here it is:
SCAR Code:program Explosion;
//Ohai
//Why did I make this? I dunno. I got bored.
var
TestArr : TStringArray;
i2 : integer;
function Explode(Delimiter : string; Str : string) : array of string;
var
DelimPos, i : integer;
Arr1 : array of string;
begin
SetArrayLength(Arr1, 100000);
i := 0;
repeat
if (pos(Delimiter, Str) = 0) then Break;
DelimPos := pos(Delimiter, Str);
Arr1[i] := Replace((copy(Str,0,DelimPos)),Delimiter,'');
Delete(Str,1,DelimPos);
i := i + 1;
until(pos(Delimiter, Str) = 0);
Arr1[i] := Str;
SetArrayLength(Arr1, i+1);
Result := Arr1;
end;
//Do whatever you want with it.
begin
TestArr := Explode('-','Runescape-Is-Fun-But-Pking-Sucks');
i2 := 0;
repeat
Writeln('Array['+IntToStr(i2)+'] = '+TestArr[i2]);
i2 := i2 + 1;
until(i2 = GetArrayLength(TestArr));
end.








Reply With Quote











