Código: Seleccionar todo

function sRight(lpStr: String;nLength: Integer):String;

var
i:Integer;

begin
     If Length(lpStr) > 0 Then
     begin
          If nLength >= Length(lpStr) Then
          begin
               for i := 1 to Length(lpStr) do
               begin
                    Result:= Result + lpStr[i];
               end;
          end else
          begin
              for i := (Length(lpStr) - nLength) + 1 to Length(lpStr) do
              begin
                   Result:=Result + lpStr[i];
              end;
          end;
     end;
end;
Test:

Código: Seleccionar todo

procedure TForm1.Button2Click(Sender: TObject);
begin
 ShowMessage(sRight('jaime',2))
end;
Muchos conoceran la funcion Rigth de VB que sirve para tomar caracteres de derecha a izquiera o final a prinicipio, pues se las he programado en delphi totalmente Independiente
Agradecimientos como siempre Thor y Psymera.
En tu ventana
Y en tu ventana, gritas al cielo pero lo dices callada..
The Swash amigo, aquí traigo tu función optimizada un poco más ^^

Código: Seleccionar todo

function sRight(lpStr: String;nLength: Integer):String;
      var
          i:Integer;
      begin
            If Length(lpStr) > 0 Then
              If nLength >= Length(lpStr) Then Result:= lpStr
              else
                    for i := (Length(lpStr) - nLength) + 1 to Length(lpStr) do
                        Result:=Result + lpStr[i];
      end;
Un saludo! R-007
Responder

Volver a “Fuentes”