Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Eliminar espacio en blanco, al final del texto. (https://www.clubdelphi.com/foros/showthread.php?t=88398)

santiago14 01-06-2015 17:22:28

Eliminar espacio en blanco, al final del texto.
 
Buenas, tengo un texto en un RichEdit, lo que quiero es eliminar los espacios en blanco al final del mismo pero, SIN PERDER EL FORMATO.
No le estoy encontrando la vuelta. Usando Trim no funciona bien la cosa pues pierde el formato de texto.

Gracias.

ecfisa 01-06-2015 20:13:23

Hola Santiago.

Fijate si te sirve de este modo:
Código Delphi [-]
procedure TrimRE(RichEdit: TRichEdit);
var
  i: Integer;
begin
  with RichEdit do
    if Lines.Count > 0 then
    begin
      i := Lines.Count-1;
      while Lines[i] = EmptyStr do
      begin
        Lines.Delete(i);
        Dec(i);
      end;
      Lines[i] := Trim(Lines[i]);
    end;
end;

Saludos :)

santiago14 17-06-2015 18:20:34

Ecfisa, hola.
Estuve probando el código que me pasaste. Funciona bien pero siempre deja el último renglón, al final.

Por ejemplo: si tengo en total 10 lineas, las tres últimas están en blanco (8, 9, 10), quita solamente dos (la 9 y 10) y queda la 8.

Santiago.

ecfisa 17-06-2015 20:19:36

Hola Santiago14.

Para eliminar el último renglón sin perder el formato:
Código Delphi [-]
procedure TrimRE(RichEdit: TRichEdit);
var
  i: Integer;
begin
  with RichEdit do
  begin
    if Lines.Count > 0 then
    begin
      i := Lines.Count-1;
      while Lines[i] = EmptyStr do
      begin
        Lines.Delete(i);
        Dec(i);
      end;
      SelStart  := Length(Text) - Length(Trim(Lines[Lines.Count-1]));
      SelLength := Length(Text);
      SelText   := '';
    end;
  end;
end;

Saludos :)

santiago14 17-06-2015 21:05:45

Ahora sí compañero. Funcionó perfecto.
Muchas gracias.


La franja horaria es GMT +2. Ahora son las 10:39:37.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi