n3ss3s
01-05-2008, 08:37 PM
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 :)
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 :)