59 lines
1.3 KiB
ObjectPascal
59 lines
1.3 KiB
ObjectPascal
|
|
unit CVBUtils;
|
|
|
|
interface
|
|
|
|
uses SysUtils;
|
|
|
|
function Trim(const cString: string): string;
|
|
function Replicate(c: char; nLen: integer): string;
|
|
function Ajusta(sCampo, sOrientacion: string; iLongitud: integer; sRelleno: char): string;
|
|
|
|
function AjustaCIF(sCampo: string): string;
|
|
|
|
|
|
implementation
|
|
|
|
function AjustaCIF(sCampo: string): string;
|
|
// Quita cualquier carácter no válido del cif,nif
|
|
var
|
|
iX: integer;
|
|
begin
|
|
Result := '';
|
|
sCampo := UpperCase(sCampo);
|
|
|
|
if length(sCampo) < 1 then
|
|
sCampo := '0';
|
|
|
|
for iX := 0 to length(sCampo) do
|
|
if (sCampo[iX] in ['0'..'9', 'A'..'Z']) then
|
|
Result := Result + sCampo[iX];
|
|
end;
|
|
|
|
|
|
function Trim(const cString: string): string;
|
|
var
|
|
I: integer;
|
|
begin
|
|
Result := TrimLeft(TrimRight(cString));
|
|
end;
|
|
|
|
function Replicate(c: char; nLen: integer): string;
|
|
begin
|
|
Result := stringOfChar(c, nLen);
|
|
end;
|
|
|
|
function Ajusta(sCampo, sOrientacion: string; iLongitud: integer; sRelleno: char): string;
|
|
begin
|
|
sCampo := Trim(sCampo);
|
|
if uppercase(sOrientacion) = 'I' then
|
|
Result := Replicate(sRelleno, iLongitud - Length(sCampo)) + sCampo
|
|
else
|
|
Result := sCampo + Replicate(sRelleno, iLongitud - Length(sCampo));
|
|
|
|
if length(Result) > iLongitud then
|
|
Result := copy(Result, 1, iLongitud);
|
|
end;
|
|
|
|
end.
|