SRL Archive - Research & Development Lounge

Explode function.


Frement

2009-09-30 23:50:35

Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.

I dont know if there is this kind of function, but i still made it. Dont know if this is any use at all :P

program ExplodeFunction;

type ExplodeArray = array[1..65536] of String;

var arr: ExplodeArray;

function explode( delimeter, str: String ): ExplodeArray;
var i, l, a: Integer;
r: ExplodeArray;
s: Char;
p: String;
begin
l := Length( str );
a := 1;
p := '';
for i := 1 to l do
begin
s := StrGet( str, i );
if ( s = delimeter ) then
begin
r[a] := p;
p := '';
a := a + 1;
end else
begin
p := p + s;
end;
end;
r[a] := p;
Result := r;
end;

begin
arr := explode( '.', 'lol.asd.fail' );
Writeln( arr[3] );
end.

Naum

2009-09-30 23:55:18

There's an Explode in SCAR, plus there is one in SRL:
srl_Explode :).

Good work though :)

Frement

2009-09-30 23:57:58

Ohh well :)

Was bored anyways :P

marpis

2009-10-01 14:51:26

Nice, but why not use TStringArray?

Frement

2009-10-01 15:53:39

Im not familiar with such :) but thx for the advice, will do so on future.