PDA

View Full Version : GetNick



n3ss3s
02-21-2008, 06:01 PM
The reason I didn't post this only in my function thread in members section is that the people who would really use this would most likely be Junior Members and registered users, who maybe enjoy cool small snippets like a function that frees you from parsing the nickname from your username.

Anyhow, here it is:



program New;
{.include SRL/SRL/Misc/ArrayLoader.scar}


Function Capitalized(C: Char): Boolean;
Begin
Result := LowerCase(C) <> C;
End;


Function GetNick(Username: String; NickLength: Integer): String;
Var
Parts, validParts: TStringArray;
z, q, w, i, c: Integer;
Begin
Parts := StrToStrArray(Username);
SetArrayLength(validParts, GetArrayLength(Parts));
For I := 0 To High(Parts) Do
If Length(Parts[i]) >= NickLength Then
Begin
validParts[z] := Parts[i];
z := z + 1;
End;
SetArrayLength(validParts, z);
For I := 0 To Z Do
Begin
For C := 1 To Length(validParts[i]) Do
If Not Capitalized(validParts[i][c]) Then
If q <= 3 Then
q := q + 1
Else
Break
Else
w := w + 1;
If q >= NickLength Then
Begin
Result := Copy(validParts[i], w + 1, q);
Exit;
End;
End;
End;


begin
Writeln(GetNick('Ran2dom Name', 3));
end.


Capitalized: Boolean by Wizzup

Wizzup?
02-21-2008, 06:11 PM
Function Capitalized(c: Char): Boolean;
Begin
Result := Lowercase(c) <> c;
End;

:p

EDIT: This doesn't work for me.
Writeln(GetNick('R A N D', 3));

n3ss3s
02-21-2008, 06:19 PM
It's not made to get nicks with spaces, spaces are for nubs :p

Dumpin
02-21-2008, 06:54 PM
Looks nice, Learned something from it, thanks :)

Smartzkid
02-21-2008, 08:42 PM
Nice

I have a challenge. Make it find the *best* nicks possible. IE: Bobby Bobbins, best nick = obb (appears twice)