FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
|||
|
|||
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. |
#2
|
||||
|
||||
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; 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; Código:
S := DupeString('0', Count) + S; |
#3
|
|||
|
|||
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; |
#4
|
|||
|
|||
Gracias
|
#5
|
||||
|
||||
Viejo o no el post, es para los proximos en llegar.
Checar la funcion StringOfChar de la unit System. Saludos |
#6
|
||||
|
||||
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... |
#7
|
||||
|
||||
bueno quiza ya fue respondida la pregunta....
pero aqui les envio lo que yo hago
para llamarlo
__________________
Dulce Regalo que Satanas manda para mi..... |
|
|
|