Autor Beitrag
CABALxx
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 174


D7 Ent
BeitragVerfasst: Sa 18.06.05 17:58 
Ahoi

Ich weiss nicht genau wie ich die frage als überschrift stellen soll ich schildere mal das problem:

ich hab nen text, besser eine textdatei mit text darin, den lese ich aus, und mit pos und copy lese ich an einer bestimmten ( pos ) stelle eine zahl aus. In diesem text werden zahlen jedoch mit Komma dargestellt, d.h. : 250000 ist im text 250,000; was ansich kein problem ist, das komma hab ich weg gemacht, ABER:

1. die zahl verändert sich, und sobald sie ein neues komma kriegt ( z.b. bei 1000000) muss ich den Programm - Code ändern, was nicht so optimal ist.

2. die Länge der zahl ändert sich: Aber man sagt ja Copy eine zeichenlänge wie lange kopiert werden soll, selbiges problem, wenn die zahl die nächste zehnerpotenz erreicht, muss ich den code ändern.

hat jemand ne idee wie man dieses lässtige problem lösen könnte`?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 18.06.05 18:19 
Kannst Du mal einen kleinen Auszug aus der Datei geben?

Welche Trennzeichen werden genutzt, um einzelzahlen auseinanderzuhalten?

Guck Dir mal StringReplace an. Vielleicht hilft der Dir etwas.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
CABALxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 174


D7 Ent
BeitragVerfasst: Sa 18.06.05 19:03 
ahoi

danke schonmal für die hilfe.

ich hatte auch schon mal überlegt, das ich an der stelle einfach die kommas gegen nichts ersetzen lassen könnte, das wäre kein problem, bleibt halt das problem, das wenn die zahl um eine stelle grösser wird, ich das programm wieder ändern muss.

aber hier mal einen auszug:

ausblenden Quelltext
1:
......class="ResourceText">E: <span id="ctrlHeader_ctrlE">2,226,250</span></td>					


das ist ein auszug aus dem strin, ist ein html quellcode, in meiner anwendung steht er in einem memo feld, memo1

diesen code habe ich bisher benutzt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
S := Memo1.Text;

    d := Copy(S,Pos('ctrlE', S)+12, 7);
    a := copy(d,1,3);
    b := copy(d,5,3);
    estr := a + b;
    //eint := StrToInt(estr);
    Edit3.Text :=  enstr;


so das ging ganz gut, bis da dann die zahl grösser wurde, nun gehts nicht mehr. das komma problem werde ich dann wohl behebn wie BenBE gesagt hat, mit replace.

aber wie mach ich das, das er sich auf die länge der zahl einstellt?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 18.06.05 19:42 
ausblenden Quelltext
1:
......class="ResourceText">E: <span id="ctrlHeader_ctrlE">2,226,250</span></td>					

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
S := Memo1.Text;

    d := Copy(S,Pos('ctrlE', S)+12, 7); // d = 6,250
    a := copy(d,1,3); // a = 6,2
    b := copy(d,5,3); // b = 0
    estr := a + b; // estr = 6,20
    //eint := StrToInt(estr);
    Edit3.Text :=  enstr;

Ich habe mal deinen Source mit den Zwischenergebnissen ergänzt. Da es zwischen 2,22 und 6,250 kein Kriterium zur Trennung gibt, ist das imho unmöglich.
Ich hoffe, dass ich mich mit den Zwischenergebnissen nicht geirrt habe, da mir das ein bisschen merkwürdig vorkommt. Allerdings habe ich das ohne Delphi abgezählt. 8)
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 18.06.05 20:24 
Sag doch gleich, dat is ne XML\HTML-File :arrow: Dafür gibt's fertige Parser.

Ansonsten:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
S := Memo1.Text;
P1 := Pos('ctrlE">', S)+7
    d := Copy(S,P1, MaxInt); // d = 2,266,250</span>...
P1 := Pos('</span', d)
    d := Copy(d,1, P1-1); // d = 2,266,250
    d := StringReplace(d, ',', '', [rfReplaceAll]); //226250

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 18.06.05 20:37 
@BenBE:
Woher weißt du, dass er die ganze Ziffern der Zahl haben will? Oder hast du nur geraten?
Laut CABALxx hat er bisher ja die richtigen Zahlen bekommen. Es gab nur Probleme, wenn die Stellenzahl sich verändert hat.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 18.06.05 20:48 
@jasocul:
Ich erstmal nur geraten. Wenn man aber die richtige Zahl einmal hat, geht das auslesen der Ziffern (wenn man die von rechts an benötigt) relativ einfach (Length im Index für Copy nutzen).

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: So 19.06.05 09:11 
Wenn man seinen Source zu Grunde legt, kann er die Länge der gesuchten Zahl nicht feststellen, da dort zwei Zahlen (nach seinem Source) stehen. Die Zahlen sind durch nichts getrennt. Demnach muss die Länge vorher bekannt sein. Und genau das ist sein Problem: Er kennt die Länge nicht.
Andere Möglichkeit: Sein Source ist falsch.
CABALxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 174


D7 Ent
BeitragVerfasst: So 19.06.05 09:22 
ahoi

also jasocul hat schon recht ich kenne einfach die länge der zahl nicht, und das problem ist das er alle 3 zeichen das komma setzt, ist aber eine zahl

2,226,250 = 2226250

das problem ist die zahl wird grösser ergo ich musste den source code bisher andauernd ändern

ich entschuldige mich mal für mein beispiel posting, da passt die zahl schon nicht mehr zum source code, das hat wohl für verwirrung gesorgt, sorry.

der code ist noch auf eine zahl eingestellt die nur ein komma hat.

also ich werd mal BenBE's code probieren, er hatte schon recht ich will die komplette zahl :D

danke schonmal vielmals werde es jetzt testen und nochmals tschuldigung für die verwirrung die ich gemacht hab


//EDIT: jop er hat recht es ist ein XML / HTML file... woher weisst du das?
CABALxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 174


D7 Ent
BeitragVerfasst: So 19.06.05 09:37 
Hab es gerade probiert:

BenBE's Code funktioniert tadellos. wunderbar

vielen vielen dank für eure hilfe

das mit dem MaxInt das ganz schön gescheit. das sehr praktisch kannte ich vorher nicht.
ist bestimmt noch öfters nützlich


vielen vielen dank :D :D :D