SRL Archive - Research & Development Lounge

RsLikeUsername


Tootoot222

2008-02-29 08:38:36

I was kinda bored, and i got to thinking, "Hey, there's no way to tell if a username is too long, or if contains invalid characters (underscores, @,#,$, etc…), is there?!" so i made this, i makes any string just like a RS username would be, it'd be useful like:


procedure DeclarePlayers;
begin
Players[0].Name:= RsLikeUsername({Insert Username here!});
//blah blah, the rest of the players code here
end;

Well, here it is:

program RsLikeUsername;

function RsLikeUsername(S: string): string;
var
i: Integer;
begin
s:= Lowercase(s);
s:= Replace(s,'_',' ');
for i:= 33 to 47 do
s:= Replace(s,Chr(i),'');
for i:= 58 to 64 do
s:= Replace(s,Chr(i),'');
for i:= 91 to 96 do
s:= Replace(s,Chr(i),'');
for i:= 123 to 126 do
s:= Replace(s,Chr(i),'');
s:= Trim(s);
s:= Capitalize(s);
i:= 0;
repeat
s:= Replace(s,' ',' ');
until(Pos(' ',s)=0);
if(Length(s)>=12) then
Delete(s,13,Length(s)-12);
Result:= s;
end;

begin
Writeln(RsLikeUsername('!@@@@. #__-_w__$#$%^&^%o___$r#%^ %$% & *(__ _*&^%$#$ ___%k^%%{} {{}{:"">?>s?":{:%^_&* ( '));
end.

And the output is:
Successfully compiled
W O R K S
Successfully executed

Wow, i made that like 50 lines shorter since i started it lol

EDIT: uhh… what's the difference between "Replace" and "ReplaceRegex"? cause i used both, and they seem to be interchangeable…

mastaraymond

2008-02-29 12:49:35

Google Regex.. Its an complex system of string finding etc..

Tootoot222

2008-03-01 01:48:56

oooo wow, that's cool, you can use other modifers with Regex