Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- ------------------------------------------------------------------------------
- PROCEDIMENTO PARA EXTRAIR LINHA DIGITAVEL
- NO FORMATO: 00000.00000 00000.000000 00000.000000 0 00000000000000
- ------------------------------------------------------------------------------
- }
- function ExtractLinhaDigitavel(dados: string): string;
- function fncValidarDigitoDaLinhaDigitavel(LinhaDigitavel: string): Boolean;
- var
- Verificador, VerificadorCorreto: String;
- begin
- Verificador := LinhaDigitavel;
- Delete(Verificador, 1, Pos(' ', Verificador));
- Delete(Verificador, 1, Pos(' ', Verificador));
- Delete(Verificador, 1, Pos(' ', Verificador));
- Verificador := Copy(Verificador, 1, 1);
- VerificadorCorreto := Modulo11LinhaDigitavel(LinhaDigitavel);
- Result := (VerificadorCorreto = Verificador);
- // MOSTRA O RESULTADO SE ENCONTROU OU NÃO O BOLETO
- // WriteLn(Result);
- end;
- function fncValidarLinhaDigitavel(linha: string): LongBool;
- var
- I: Integer;
- begin
- Result := (linha[6] = '.') and
- (linha[12] = ' ') and
- (linha[18] = '.') and
- (linha[25] = ' ') and
- (linha[31] = '.') and
- (linha[38] = ' ') and
- (linha[40] = ' ');
- if Result then
- begin
- for I:=1 to 54 do
- begin
- if ((I<>6)and(I<>12)and(I<>18)and(I<>25)and(I<>31)and(I<>38)and(I<>40)) then
- begin
- if Pos(linha[I], '0123456789') = 0 then
- begin
- Result := False;
- Break;
- end;
- end;
- end;
- end;
- end;
- var
- I: Integer;
- SCAN: string;
- begin
- Result := '';
- for I:=1 to Length(dados) do
- begin
- SCAN := Copy(dados, I, 54);
- if fncValidarLinhaDigitavel(SCAN) then
- begin
- if fncValidarDigitoDaLinhaDigitavel(SCAN) then
- begin
- // Caso os 54 caracteres contém apenas numeros, pontos, espaços e o digito verificador estiver correto, então é uma linha digitavel.
- Result := SCAN;
- // WriteLn(Result);
- Break;
- end;
- end;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment