Fórum Problema com loop !!!! #293780
30/08/2005
0
LBArquivos:
Parte da string:
O problema é o seguinte:
O usuario colocou a orden do LBArquivos oposta a da string, o no meu cod. so
alteraria a 1ª linha da string alguem sabe como que posso resolver isso ?????
Guilherme
Curtir tópico
+ 0Posts
30/08/2005
Rjun
Gostei + 0
30/08/2005
Massuda
Gostei + 0
30/08/2005
Guilherme
Gostei + 0
30/08/2005
Guilherme
a principio era so o nome do arquivo sem caminho so que ai entrou mais coisas tipo o cid: o cod ki completo para fazer a alteraçao eh esse :
var Htm,Newarq : TStringList; I, J, l, t: Integer; PosIni: Integer; PosFim: Integer; ContaCaract: Integer; MeuTexto: string; MinhaFrase,resultado: string; begin Htm:=TStringList.Create; Newarq:=TStringList.Create; Htm.LoadFromFile(edtlocal.Text); for J := 0 to Htm.Count-1 do begin MeuTexto := htm[J]; //não pra colocar "I" no Lines e sim "J" era Memo1.Lines[I]; if Pos(´src="´, MeuTexto) > 0 then //Linha adicionada begin PosIni := Pos(´src="´, MeuTexto) + 5; ContaCaract := 0; for I := PosIni to Length(MeuTexto) do begin if MeuTexto[I] = ´"´ then // fim da src begin MinhaFrase := Copy(MeuTexto, PosIni, ContaCaract); for t := 0 to LBArquivos.Lines.Count-1 do if Pos(ExtractFileName(LBArquivos.lines[t]),MeuTexto) <> 0 then begin resultado:=´cid:´+LBArquivos.lines[t]; Newarq.Add(StringReplace(MeuTexto, MinhaFrase, resultado, [])); LBArquivos.lines.Delete(t); end; end; Inc(ContaCaract); end; end else //else adicionado begin Newarq.Add(htm[J]); Continue; end; end; end;
Gostei + 0
30/08/2005
Massuda
... for t := LBArquivos.Lines.Count-1 downto 0 do if Pos(ExtractFileName(LBArquivos.lines[t]),MeuTexto) <> 0 then begin resultado:=´cid:´+LBArquivos.lines[t]; Newarq.Add(StringReplace(MeuTexto, MinhaFrase, resultado, [])); LBArquivos.lines.Delete(t); end; end; ...
Gostei + 0
30/08/2005
Guilherme
Gostei + 0
30/08/2005
Massuda
Gostei + 0
30/08/2005
Guilherme
Gostei + 0
30/08/2005
Massuda
... for J := 0 to Htm.Count - 1 do begin MeuTexto := htm[J]; if Pos(´src="´, MeuTexto) > 0 then begin PosIni := Pos(´src="´, MeuTexto) + 5; ContaCaract := 0; for I := PosIni to Length(MeuTexto) do begin if MeuTexto[I] = ´"´ then begin Break; end; Inc(ContaCaract); end; if ContaCaract > 0 then begin MinhaFrase := Copy(MeuTexto, PosIni, ContaCaract); for t := 0 to LBArquivos.Lines.Count - 1 do begin if Pos(ExtractFileName(LBArquivos.lines[t]), MeuTexto) <> 0 then begin resultado := ´cid:´ + LBArquivos.lines[t]; Newarq.Add(StringReplace(MeuTexto, MinhaFrase, resultado, [])); Break; end; end; // pode acontecer de não encontrar MinhaFrase em LBArquivos end else begin // se o HTML estiver errado, pode acontecer de ContaCaract = 0 end; end else begin Newarq.Add(MeuTexto); end; end; ...
Gostei + 0
01/09/2005
Guilherme
var
Htm,Newarq : TStringList;
lhtml,LAcharFinal,Larq: Integer;
PosIni: Integer;
PosFim: Integer;
ContaCaract: Integer;
MeuTexto: string;
MinhaFrase,resultado: string;
begin
for LHtml := 0 to Htm.Count -1 do begin
MinhaFrase:= htm[LHtml];
if pos(´SRC="´,UpperCase(MinhaFrase)) <> 0 then begin
PosIni:=pos(´SRC="´,UpperCase(MinhaFrase)) + 5;
ContaCaract:=0;
for LAcharFinal := PosIni to length(MinhaFrase) do begin
if MinhaFrase[LAcharFinal] = ´"´ then begin {eh o fim do texto dentro das aspas}
MeuTexto:= copy(MinhaFrase,PosIni,ContaCaract);
MeuTexto:=StringReplace(MeuTexto,´¬20´,´ ´,[rfReplaceAll]);
MinhaFrase:=StringReplace(MinhaFrase,´¬20´,´ ´,[rfReplaceAll]);
for Larq := 0 to LbArquivos.Lines.Count -1 do
if Pos(ExtractFileName(LbArquivos.Lines[Larq]),MeuTexto) <> 0 then begin
resultado:=´cid:´+ LbArquivos.Lines[Larq];
Newarq.Add(StringReplace(MinhaFrase,MeuTexto,resultado,[rfReplaceAll]));
resultado:=´´;
Break;
end; {1º if dentro do loop Larq}
Break;
end else {si ainda nao cababo o texto dentro das aspas intao}
Inc(ContaCaract)
end; {2º laço for tag >> for LAcharFinal := PosIni to length(MinhaFrase) do begin }
end else begin {end da 1º compareçao "if" }
Newarq.Add(Htm[Lhtml]);
Continue;
end; {end do else}
end ; {end do 1º laço for referente a tag >> for LHtml := 0 to Htm.Count -1 do begin}
end;
vlw ai todo mundo mais so resumindo nao tava dando certo por falta de um break !!!!![/code]
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)