Fórum Copiando String. #61978
14/01/2008
0
Qual o comando que uso para copiar string, uso o borland c++ 2006.
Estou precisando dividir um string para formatacao de cpf e nao estou conseguindo.
Se algum poder me ajudar.
desde ja muito obrigado.
Roberto Paraiso.
Roberto Paraiso
Curtir tópico
+ 0Posts
16/01/2008
Roberto Paraiso
estou querendo pegar um string de um edit e formatar em tempo de execucao no onChange, ex
12345678901 para 123.456.789-01
Roberto Paraiso.
Gostei + 0
16/01/2008
Roberto Paraiso
{formata CNPJ/CPF inserindo simbolos necessários}
Function Formata_CNPJ_CPF(Texto: String): String;
Begin
// Limpar simbolos padrões do CNPJ e CPF
Texto:=DeletaCaract(Texto,´-´);
Texto:=DeletaCaract(Texto,´/´);
Texto:=DeletaCaract(Texto,´.´);
// 14 digitos significa CNPJ
If length(Texto)=14 then
begin
result :=
copy(Texto, 1, 2) + ´.´ +
copy(Texto, 3, 3) + ´.´ +
copy(Texto, 6, 3) + ´/´ +
copy(Texto, 9, 4) + ´-´ +
copy(Texto, 13, 2);
end;
// 11 digitos significa CPF
If length(Texto)=11 then
begin
result := copy(Texto, 1, 3) + ´.´ +
copy(Texto, 4, 3) + ´.´ +
copy(Texto, 7, 3) + ´-´ +
copy(Texto, 10, 2);
end;
End;
Roberto Paraiso.
Gostei + 0
17/01/2008
Rodc
/* formata CNPJ/CPF inserindo simbolos necessários */
AnsiString Formata_CNPJ_CPF(AnsiString Texto)
{
// Limpar simbolos padrões do CNPJ e CPF
Texto = StringReplace(Texto, "-", "", TReplaceFlags() << rfReplaceAll);
Texto = StringReplace(Texto, "/", "", TReplaceFlags() << rfReplaceAll);
Texto = StringReplace(Texto, ".", "", TReplaceFlags() << rfReplaceAll);
// 14 digitos significa CNPJ
if (Texto.Length() == 14)
{
return Texto.SubString(1, 2) + "." +
Texto.SubString(3, 3) + "." +
Texto.SubString(6, 3) + "/" +
Texto.SubString(9, 4) + "-" +
Texto.SubString(13, 2);
}
// 11 digitos significa CPF
else if (Texto.Length() == 11)
{
return Texto.SubString(1, 3) + "." +
Texto.SubString(4, 3) + "." +
Texto.SubString(7, 3) + "-" +
Texto.SubString(10, 2);
}
else
return "";
}Gostei + 0
17/01/2008
Roberto Paraiso
Muito Obrigado mesmo cara.
Roberto Paraiso.
Gostei + 0
17/01/2008
Rodc
Sugiro fazer no OnExit().
Gostei + 0
17/01/2008
Roberto Paraiso
Roberto Paraiso.
Gostei + 0
17/01/2008
Rodc
Infelismente não tenho.
Gostei + 0
17/01/2008
Roberto Paraiso
Roberto Paraiso.
Gostei + 0
18/01/2008
Rodc
Se o código não for muito extenso eu converto, infelizmente não posso perder muito tempo.
Posta o código aí.
Gostei + 0
18/01/2008
Roberto Paraiso
var
n1,n2,n3,n4,n5,n6,n7,n8,n9: integer;
d1,d2: integer;
digitado, calculado: string;
begin
n1:=StrToInt(num[1]);
n2:=StrToInt(num[2]);
n3:=StrToInt(num[3]);
n4:=StrToInt(num[4]);
n5:=StrToInt(num[5]);
n6:=StrToInt(num[6]);
n7:=StrToInt(num[7]);
n8:=StrToInt(num[8]);
n9:=StrToInt(num[9]);
d1:=n9*2+n8*3+n7*4+n6*5+n5*6+n4*7+n3*8+n2*9+n1*10;
d1:=11-(d1 mod 11);
if d1>=10 then d1:=0;
d2:=d1*2+n9*3+n8*4+n7*5+n6*6+n5*7+n4*8+n3*9+n2*10+n1*11;
d2:=11-(d2 mod 11);
if d2>=10 then d2:=0;
calculado:=inttostr(d1)+inttostr(d2);
digitado:=num[10]+num[11];
if calculado=digitado then
cpf:=true
else
cpf:=false;
end;
function cgc(num: string): boolean;
var
n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12: integer;
d1,d2: integer;
digitado, calculado: string;
begin
n1:=StrToInt(num[1]);
n2:=StrToInt(num[2]);
n3:=StrToInt(num[3]);
n4:=StrToInt(num[4]);
n5:=StrToInt(num[5]);
n6:=StrToInt(num[6]);
n7:=StrToInt(num[7]);
n8:=StrToInt(num[8]);
n9:=StrToInt(num[9]);
n10:=StrToInt(num[10]);
n11:=StrToInt(num[11]);
n12:=StrToInt(num[12]);
d1:=n12*2+n11*3+n10*4+n9*5+n8*6+n7*7+n6*8+n5*9+n4*2+n3*3+n2*4+n1*5;
d1:=11-(d1 mod 11);
if d1>=10 then d1:=0;
d2:=d1*2+n12*3+n11*4+n10*5+n9*6+n8*7+n7*8+n6*9+n5*2+n4*3+n3*4+n2*5+n1*6;
d2:=11-(d2 mod 11);
if d2>=10 then d2:=0;
calculado:=inttostr(d1)+inttostr(d2);
digitado:=num[13]+num[14];
if calculado=digitado then
cgc:=true
else
cgc:=false;
end;
end.
desculpa pelo incomodo
obrigado
Roberto Paraiso.
Gostei + 0
18/01/2008
Rodc
Gostei + 0
18/01/2008
Rodc
bool cpf(AnsiString num)
{
int n1,n2,n3,n4,n5,n6,n7,n8,n9;
int d1,d2;
AnsiString digitado, calculado;
n1=StrToInt(num[1]);
n2=StrToInt(num[2]);
n3=StrToInt(num[3]);
n4=StrToInt(num[4]);
n5=StrToInt(num[5]);
n6=StrToInt(num[6]);
n7=StrToInt(num[7]);
n8=StrToInt(num[8]);
n9=StrToInt(num[9]);
d1=n9*2+n8*3+n7*4+n6*5+n5*6+n4*7+n3*8+n2*9+n1*10;
d1=11-(d1 ¬ 11);
if (d1>=10)
d1=0;
d2=d1*2+n9*3+n8*4+n7*5+n6*6+n5*7+n4*8+n3*9+n2*10+n1*11;
d2=11-(d2 ¬ 11);
if (d2>=10)
d2=0;
calculado=IntToStr(d1)+IntToStr(d2);
digitado=AnsiString(num[10]) + AnsiString(num[11]);
return calculado==digitado;
}
bool cgc(AnsiString num)
{
int n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12;
int d1,d2;
AnsiString digitado, calculado;
n1=StrToInt(num[1]);
n2=StrToInt(num[2]);
n3=StrToInt(num[3]);
n4=StrToInt(num[4]);
n5=StrToInt(num[5]);
n6=StrToInt(num[6]);
n7=StrToInt(num[7]);
n8=StrToInt(num[8]);
n9=StrToInt(num[9]);
n10=StrToInt(num[10]);
n11=StrToInt(num[11]);
n12=StrToInt(num[12]);
d1=n12*2+n11*3+n10*4+n9*5+n8*6+n7*7+n6*8+n5*9+n4*2+n3*3+n2*4+n1*5;
d1=11-(d1 ¬ 11);
if (d1>=10)
d1=0;
d2=d1*2+n12*3+n11*4+n10*5+n9*6+n8*7+n7*8+n6*9+n5*2+n4*3+n3*4+n2*5+n1*6;
d2=11-(d2 ¬ 11);
if (d2>=10)
d2=0;
calculado=IntToStr(d1)+IntToStr(d2);
digitado=AnsiString(num[13])+AnsiString(num[14]);
return calculado == digitado;
}Gostei + 0
24/01/2008
Roberto Paraiso
Roberto Paraiso
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)