Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 21-10-2003
buitrago buitrago is offline
Miembro
 
Registrado: sep 2003
Posts: 156
Poder: 21
buitrago Va por buen camino
Rellenar con 0....

Neceito una function que me rellene con 0 un string

Esto es que yo tengo un string y necesito rellenar con 0 a la izq ese mismo estrig, según la cantidad de 0 que especifique.

Hay algo escvrito en Delphi o el mismo Delphi me puede ayudar ....

Gracias.
Responder Con Cita
  #2  
Antiguo 21-10-2003
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Poder: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
Si lo que necesitas es escribir un número con tantos ceros a la izquierda como sean necesarios para alcanzar determinada longitud quizá te sirva esta función:

Código:
function LPad(N: Integer; Count: Integer): String;
begin
  Result := Format('%.*d', [Count, N]);
end;
Por ejemplo:

LPad(84, 5) --> '00084'
LPad(84, 7) --> '0000084';

Para otros casos en que la cadena rellenar no sea un número me parece, y espero estar equivocado, que no hay una función de tipo Pad en Delphi pero podrías construirla tu mismo usando un ciclo for para anexar los ceros:

Código:
for I := 1 to Count do
  S := '0' + S;
o bien, si tu versión de Delphi la trae, usar la función DupeString de la unidad StrUtils:

Código:
S := DupeString('0', Count) + S;
// Saludos
Responder Con Cita
  #3  
Antiguo 21-10-2003
brandolin brandolin is offline
Miembro
 
Registrado: jul 2003
Ubicación: Mendoza
Posts: 324
Poder: 21
brandolin Va por buen camino
Yo he ceado una funcion como esta, no se si esta obtimizada pero funciona.


Function LlenarCeros(Original: String; long: Integer): String;
var x : integer;
Temp : String;
begin
Temp := '';
For X := 1 to Long-Length(Original) do
Temp:= '0' + Temp;
LlenarCeros := Temp + Original;
end;
Responder Con Cita
  #4  
Antiguo 20-11-2003
buitrago buitrago is offline
Miembro
 
Registrado: sep 2003
Posts: 156
Poder: 21
buitrago Va por buen camino
Gracias
Responder Con Cita
  #5  
Antiguo 03-11-2011
Avatar de juanlaplata
juanlaplata juanlaplata is offline
Miembro
 
Registrado: ene 2007
Ubicación: La Plata, Bs. As. (Argentina)
Posts: 212
Poder: 18
juanlaplata Va por buen camino
Viejo o no el post, es para los proximos en llegar.
Checar la funcion StringOfChar de la unit System.
Saludos
Responder Con Cita
  #6  
Antiguo 17-11-2011
Avatar de thelibmx
thelibmx thelibmx is offline
Miembro
 
Registrado: mar 2007
Posts: 515
Poder: 18
thelibmx Va por buen camino
Wink Rellenar Strings con caracteres

Pues para las nuevas generaciones va

function LPad(S: String; Ch: Char; Len: Integer): String;
begin
Result := StringOfChar(Ch, Len - Length(S)) + S;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
e2.text:=(LPad(e1.text,'0',10));
end;
__________________
En movimiento...
Responder Con Cita
  #7  
Antiguo 17-11-2011
Avatar de oscarac
[oscarac] oscarac is offline
Miembro Premium
 
Registrado: sep 2006
Ubicación: Lima - Perú
Posts: 2.009
Poder: 20
oscarac Va por buen camino
bueno quiza ya fue respondida la pregunta....
pero aqui les envio lo que yo hago

Código Delphi [-]
 
function Llenar(strValue: String; intNewWidth: Integer): String;
var intOldWidth, I: Integer;
begin
  try
    strValue := Trim (StrValue);
    if strValue = '' then
      strValue := '0';
    if StrToInt(strValue) < 0 then
      strValue := '0';
  except
    on EConvertError do strValue := '0';
  end;
  intOldWidth := Length(strValue);
  if intOldWidth < intNewWidth then
    for I := 1 to intNewWidth - intOldWidth do
      strValue := '0' + strValue;
  Result := strValue;
end;


para llamarlo

Código Delphi [-]
 
  edtNumIngreso.Text := Llenar(edtNumIngreso.Text, 11);
__________________
Dulce Regalo que Satanas manda para mi.....
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 20:59:27.


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