GARANTIR DESCONTO

Fórum Delimiter no Delphi: Como ignorar espaços vazios? #579580

31/03/2017

0

Estou com o segunite problema , estou usando o '@' como meu delimiter porém tem casos que meus campos possuem nomes compostos com 'Santa Cruz' como faço para que meu delimiter ignore esse espaço vazio e jogue no meu array o nome completo não apenas o 'Santa' ?
Segue minha procedure , desde já agradeço !
procedure TForm1.Button6Click(Sender: TObject);
Var
Arq : TextFile;
Arqorigem, Linha : String;
Str : TStringList;
Dia : string;
begin
AssignFile(Arq,Edit1.Text);
str := TStringList.Create;
Reset(Arq);
ReadLn(Arq, Linha);
while not eof(Arq) do
Begin
try
str.Delimiter := '@';
str.DelimitedText := Linha;
DsInsere.DataSet.Open;
DsInsere.DataSet.Insert;
qInsere.FieldByName('UF').Value := Trim(Str[0]);
qInsere.FieldByName('LOCA_').Value  := Str[4];
qInsere.FieldByName('CEP8').Value := Str[6];
qInsere.FieldByName('NOME').Value  := Str[8];
qInsere.FieldByName('BAIINI').Value := Str[10];
qInsere.FieldByName('TIPO').Value := Str[12];
DsInsere.DataSet.Post;
except
ShowMessage('Erro ao importar arquivo.');
Abort;
end;
Readln(Arq, Linha); 
end; 
CloseFile(Arq);
ShowMessage('Arquivo importado com sucesso.');
end;


Estrutura do meu txt : MG@nm@@nm@Paris@nm@32340460@nm@Contagem@nm@Santa Cruz Industrial@nm@Praça @nm@@nm@
Rodrigo Oliveira

Rodrigo Oliveira

Responder

Posts

05/04/2017

Wesley Yamazack

Opa Rodrigo, blz?

Fiz um exemplo adaptado... segui o teu exemplo, mas fiz algumas mudanças, ok?

procedure TForm1.Button1Click(Sender: TObject);
Var
  s : String;
  Arq, Str_Lista : TStringList;
  i: integer;
begin
  Arq := TStringList.Create;
  Str_Lista := TStringList.Create;
  Arq.LoadFromFile(ExtractFileDir(Application.ExeName)+'\\conteudo.txt');

  Str_Lista.Delimiter := '@';
  Str_Lista.QuoteChar := ' ';
  Str_Lista.StrictDelimiter := True;

  for I := 0 to Arq.Count -1 do
  begin
    Str_Lista.DelimitedText := Arq.Strings[I];
    s := s + #13 +
         Str_Lista[1] + #13 +
         Str_Lista[2] + #13 +
         Str_Lista[3] + #13 +
         Str_Lista[4] + #13 +
         Str_Lista[5] + #13 +
         Str_Lista[6] + #13 +
         Str_Lista[7] + #13 +
         Str_Lista[8] + #13 +
         Str_Lista[9] + #13 +
         Str_Lista[10] + #13 +
         Str_Lista[11] + #13 +
         Str_Lista[12] + #13 +
         Str_Lista[13] + #13 +
         Str_Lista[14] + #13 +
         Str_Lista[15] + #13 +
         Str_Lista[16];
  end;
  ShowMessage(S);

end;


Veja se essa ideia irá lhe ajudar :)=

Você pode dar uma lida tbm num artigo meu sobre isso. Segue o link:

[url]https://www.devmedia.com.br/usando-separador-no-listbox-delphi/23946[/url]

Qualquer coisa estamos por aqui :)
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar