AuthorMessage
Meka][Meka
Unstopable
Posts: 700

ok, ive wrote a quick slow, stupid,. bad coded function to strip nicks temporarily, til i come up with better method, but i'm gonna post here, so if anyone has good ideas as to accompish the task, i'd like to hear them if you're up to it,
Code:

function TMainFRM.StripNick(sNick: string): string;
var
  nick: string;
  len : integer;
begin
  if Pos(']',sNick) > 0 then begin
    len := Length( Copy( sNick, 1, Pos( ']',sNick ) ) );
    nick := Copy(sNick,Pos(']',sNick)+1,Length(sNick)-len);
  end;
  if Pos(')',nick) > 0 then begin
    len := Length( Copy( nick, 1, Pos( ')',nick ) ) );
    nick := Copy(nick,Pos(')',nick)+1,Length(nick)-len);
  end;
  if Pos('[',nick) > 0 then begin
    len := Length( Copy( nick, 1, Pos( '[',nick ) ) );
    nick := Copy(nick,Pos('[',nick)+1,Length(nick)-len);
  end;
  if nick <> '' then
    if nick[1] = '-' then
      nick := Copy(nick,2,Length(nick)-1);
  Result := nick;
end;

ok basically '[blah™]Blah' becomes 'Blah' or '[-TE-]-Meka][Meka' becomes 'Meka', but sometimes it messes up due to other chars, i also want to remove such (tm) chars and other misc things, anyone got any ideas please do post, thanks,
-/Meka][Meka
bluebear
n00b
Posts: 32

Regular expressions would be really good for this Meka
Meka][Meka
Unstopable
Posts: 700

Quoted from bluebear
Regular expressions would be really good for this Meka

duno about using them in delphi....delphi aint so powerful with strings.
but: http://www.renatomancuso.com/software/dpcre/dpcre.htm
Meka][Meka
Unstopable
Posts: 700

ok.. im using a lib RegExpr, bluebear you got any examples on stripping nick using regexpr, im crap at using regexpressions Lol, wud appreciate it, thanks,
Meka][Meka
Unstopable
Posts: 700

well im not sure if this is right but it seem so to work, unless thers unknown chars, which will also be removed.... with 'CleanNick'
Code:

function TPipel.StripNick(Sender: string): string;
const
  Format = '[_a-zA-Z\d\-\.]+$';
var
  r : TRegExpr;
begin
  Result := '';
  r := TRegExpr.Create;
  try // ensure memory clean-up
    r.Expression := Format;
    if r.Exec (Sender) then repeat
      Result := Result + r.Match [0];
    until not r.ExecNext;
  finally r.Free;
  end;
end;

Mickey
Ametuar
Posts: 115

It looks OK. This RegEXp looks cool. I'm gonna use it. If I were you I would change the expression to:
Code:
...
Format = '^\[_a-zA-Z\d\-\.\] + $';
...

Meka][Meka
Unstopable
Posts: 700

Quoted from Mickey
It looks OK. This RegEXp looks cool. I'm gonna use it. If I were you I would change the expression to:
Code:
...
Format = '^\[_a-zA-Z\d\-\.\] + $';
...


doesnt work like this ^
but i changed it to:
Code:

function TPipel.StripNick(Sender: string): string;
const
  Format = '[_a-zA-Z\d\.]+$';
var
  r : TRegExpr;
begin
  Result := '';
  r := TRegExpr.Create;
  try // ensure memory clean-up
    r.Expression := Format;
    if r.Exec (Sender) then repeat
      Result := r.Match [0];
    until not r.ExecNext;
  finally r.Free;
  end;
end;