TStingList inlezen met delphi 7

Pagina: 1
Acties:

  • Geodan
  • Registratie: Maart 2003
  • Laatst online: 20-06-2025
als ik de volgende tekst wil inlezen met TStringList

map.bboxwest = 50000
map.bboxsouth = 300000
map.bboxeast = 250000
map.bboxnorth = 625000

krijg ik het volgende probleem.

code:
1
2
3
4
5
6
7
8
test := TStringList.Create;
test.LoadFromFile('d:\mapswing manager\programmeren\fileopen\durp.properties');

index := test.IndexOfName('map.bboxwest    ');  {dit werkt wel omdat ik spaties op het eind neerzet}
Edit6.Text := IntToStr(index);

index := test.IndexOfName('map.bboxwest'); {werkt niet.}
Edit6.Text := IntToStr(index);

ik kan ook niet de hele lijst doorlopen en de namen trimmen, omdat test.Names[I] readonly is.

weet iemand een oplossing zodat ik map.bboxwest,map.bboxsouth etc. kan uitlezen zonder die irritante spaties

[ Voor 4% gewijzigd door whoami op 21-03-2003 10:05 ]


  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 21:27

Creepy

Tactical Espionage Splatterer

Waarom zoek je m.b.v. indexofname? De index die je terugkrijgt is NIET de waarde die achtter de = staat.
En waarom heb je hier geen TInifile voor gebruikt?

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


Verwijderd

Je zult de spaties voor de = dan op een andere manier moeten verwijderen
iets dergelijks als dit:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
for i:= 0 to test.count-1 do
begin
  repeat
    equalpos:=pos('=',test[i]);
    if (equalpos>0) and (test[i][equalpos-1]=' ') then
    begin
      spacefound:=true;
      test[i]:=Copy(test[i],1,equalpos-2)+Copy(test[i],equalpos,length(Test[i])-equalpos+1);
    end
    else
      spacefound:=false;

  until not spacefound;
end;

[ Voor 7% gewijzigd door Verwijderd op 21-03-2003 10:33 ]


  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 21:27

Creepy

Tactical Espionage Splatterer

Verwijderd schreef op 21 March 2003 @ 10:28:
Je zult de spaties voor de = dan op een andere manier moeten verwijderen
iets dergelijks als dit:

for i:= 0 to test.count-1 do
begin
repeat
equalpos:=pos('=',test[i]);
if (equalpos>0) and test[i][equalpos-1]=' ' then
begin
spacefound:=true;
test[i]:=Copy(test[i],1,equalpos-2)+Copy(test[i],equalpos,length(Test[i])-equalpos+1);
end
else
spacefound:=false;

until not spacefound;
end;
In de names array zit alles wat VOOR de = staat, dus dat is helemaal niet nodig.

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


  • Geodan
  • Registratie: Maart 2003
  • Laatst online: 20-06-2025
In de names array zit alles wat VOOR de = staat, dus dat is helemaal niet nodig.
daar gaat het juist wel om, want als ik

index := test.IndexOfName('map.bboxwest'); wil doen mogen daar geen spaties voor staan

maar ik heb het al opgelost met

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  test := TStringList.Create;
  test.LoadFromFile('d:\mapswing manager\programmeren\file open\durp.properties');
  for I := 0 to test.Count - 1 do
  begin
    links := Trim(test.Names[I]);
    rechts:= Trim(test.ValueFromIndex[I]);
    if links <> '' then
    begin
      test[I] := links;
      if rechts <> '' then
      begin
        test[I] := test[I] + '=' + rechts;
      end;
    end;

Verwijderd

De TS wil in zijn routines geen spaties gebruiken. De spaties voor de = zijn dus het probleem. Als in zijn invoer bestand spaties staan, moet hij ze dus verwijderen voordat hij de stringlist verder gebruikt.
De conversie routine kan dan wel wat makkelijker en de repeat block kan weg

test[i]:=Trim(Names[i]))+Copy(test[i],equalpos,length(Test[i])-equalpos+1);

  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 21:27

Creepy

Tactical Espionage Splatterer

Vraag ik me alleen af waarom je hier geen TIniFile voor gebruikt die dit soort dingen allemaal al voor je afhandelt.

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 21:27

Creepy

Tactical Espionage Splatterer

Verwijderd schreef op 21 March 2003 @ 10:41:
De TS wil in zijn routines geen spaties gebruiken. De spaties voor de = zijn dus het probleem. Als in zijn invoer bestand spaties staan, moet hij ze dus verwijderen voordat hij de stringlist verder gebruikt.
De conversie routine kan dan wel wat makkelijker en de repeat block kan weg

test[i]:=Trim(Names[i]))+Copy(test[i],equalpos,length(Test[i])-equalpos+1);
Ja.. maar de NAMES array geeft alles wat VOOR de = straat terug, dus hier kan meteen trim op worden gebruikt. Zie ook de oplossing van de TS ;)

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney

Pagina: 1