SRL Archive - Research & Development Lounge

String Stuffz


n3ss3s

2008-01-05 15:37:25

For all your text manipulation needs:


program New;

Var
A: TStringArray;

Function Explode(Sep, Text: String): TStringArray;
Var
L, Le, I: Integer;
Begin
SetArrayLength(Result, 1);
L := Length(Text);
For I := 1 To L Do
If Text[i] <> Sep Then
Begin
Le := High(Result);
Result[Le] := Result[Le] + Text[i];
End Else
SetArrayLength(Result, GetArrayLength(Result) + 1);
End;


Function AlphabeticalPos(Letter: String): Integer;
Var
I: Integer;
A, L: String;
Begin
A := 'abcdefghijklmnopqrstuvwxyz';
L := LowerCase(Letter);
For I := 1 To 26 Do // Case would've been boring =]
If A[i] = L Then
Begin
Result := I;
Exit;
End;
End;


Function OrderToAlphabet(Text: String): TStringArray;
//* The A's will be found in Result[0] etc.
Var
I, L, AP: Integer;
Begin
SetArrayLength(Result, 26);
L := Length(Text);
For I := 1 To L Do
Begin
AP := AlphabeticalPos(Text[i]);
Result[AP - 1] := Result[AP - 1] + Text[i];
End;
End;


Var
I: Integer;

begin
A := OrderToAlphabet('ababcdcd');
For I := 0 To High(A) Do
Writeln(A[i]);

end.

EDIT: Explode isn't originally my idea ofcourse, I just wanted to try to do it that way :)

R0b0t1

2008-01-05 16:54:31

Bubble. Sorting. Is. Slow. As. Hell.

jhildy

2008-01-05 20:29:01

what does explode exactly do?

Boreas

2008-01-05 23:53:38

program New;

Var
A: String;
B: TStringArray;

Function Explode(Sep, Text: String): TStringArray;
Var
L, Le, I: Integer;
Begin
SetArrayLength(Result, 1);
L := Length(Text);
For I := 1 To L Do
If Text[i] <> Sep Then
Begin
Le := High(Result);
Result[Le] := Result[Le] + Text[i];
End Else
SetArrayLength(Result, GetArrayLength(Result) + 1);
End;
var i:integer;
begin
A := 'hello/nice/to/meet/you';
B := Explode('/',A);
for i:=0 to 4 do
writeln(B[i]);
end.


Successfully compiled
hello
nice
to
meet
you
Successfully executed

Wizzup?

2008-01-06 05:45:04

SRL/Misc/arrayloader.scar

;)

n3ss3s

2008-01-06 06:19:55

Sweet, but tell me, in what occasion I would have to turn string to tpointarray instead of intz?