Autor Beitrag
basner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Di 09.06.09 14:06 
Hallo.

Ich habe folgenden String:

ausblenden Quelltext
1:
Anrede   StraßenteilNameVorname   Straßenende, Hausnummer,PLZ,Ort					

Wie bekomme ich das Straßenteile an das Straßenende habe es schon mit Pos probiert und Copy leider funktioniert das nicht.

Vielen Dank


Hatte es so probiert:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
    IndexMerken3 := 0;
        IndexMerken4 := 0;
        StrassenTeilgefunden := false;
        gross := false;
        for i4 := 1 to length(FileContents) do begin

                   if (FileContents[i4] in ['A'..'Z','Z'..'A'])then
                   begin

                        gross := true;
                   end;

                   if gross then begin

                   if (FileContents[i4+1in ['A'..'Z','Z'..'A'])then
                        begin
                        if IndexMerken3 = 0
                        then IndexMerken3 := i4;
                        end;


                     if ((IndexMerken3 > 0and (FileContents[i4] in ['A'..'Z','Z'..'A']) and (StrassenTeil2 = ''))
                     then IndexMerken3 := 0;

                     if IndexMerken3 < i4 then begin
                             if ((IndexMerken3> 0and (FileContents[i4] in[' '])and (StrassenTeil2 = ''))
                             then IndexMerken4 := i4;
                     end;


                     if ((IndexMerken4 > 0and (StrassenTeil2 = '')) then
                     begin
                      //Gefundenen Datensatz kopieren
                      StrassenTeil2 := Copy(FileContents,IndexMerken3,(IndexMerken4-1) - (IndexMerken3-1));
                      //Kopierten Datensatz dann an alter Stelle löschen
                      Delete(FileContents,IndexMerken3,(IndexMerken4-1) - (IndexMerken3-1));


                    end;


                     if ((FileContents[i4] in [' ']) and (IndexMerken4 > 0and (StrassenTeil2 <> '')) //or ((FileContents[Strassensuche] in [' '])and(FileContents[Strassensuche] in ['a'..'z','z'..'a']) and (IndexMerken3 > 0) and (StrassenTeil <> ''))
                     then begin


                                     if (FileContents[i4+1in [' ']) then
                                     begin
                                      vorname2 := true;
                                     end;


                                     if vorname2 and (FileContents[i4+1in['a'..'z','z'..'a','.','9'..'0','0'..'9']) then
                                          begin
                                               insert(StrassenTeil2,FileContents,i4+1);
                                          IndexMerken3 := 0;
                                          IndexMerken4 := 0;
                                          vorname2 := false;
                                    end;

                       gross := false;
                      end;//gross

                     end;


Moderiert von user profile iconNarses: Code- durch Delphi-Tags ersetzt
oki
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

Win XP
Delphi 2007 Prof
BeitragVerfasst: Di 09.06.09 15:12 
Da seh ich mal mächtig schwarz. Da der Name direkt hinter Straßenteil ohne Leerzeichen oder sonstiges Trennzeichen beginnt sehe ich keine Möglichkeit das sauber zu trennen, außer du hast eine feste Länge für Straßenteil definiert. Dann läßt sich was machen. Die Auflistung der einzelnen Elemente des Strings erscheint mir auch sehr abenteuerlich, mal Leerzeichen mal Komma als Trenner, mal gar kein Trennzeichen. Wo kommt denn das her?

Gruß oki

_________________
42
basner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Di 09.06.09 15:19 
Habe es wie folgt gelöst funktioniert einwandfrei.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
  gross := false;
        for i4 := 0 to length(FileContents) do begin

              if gross = false then begin
                    if ((FileContents[i4] in ['A'..'Z','Z'..'A'])and(FileContents[i4+1in ['a'..'z','z'..'a']) and (FileContents[i4+2in ['a'..'z','z'..'a'])and (FileContents[i4+3in ['a'..'z','z'..'a'])and (FileContents[i4+4in ['a'..'z','z'..'a'])and (FileContents[i4+5in ['a'..'z','z'..'a'])and (FileContents[i4+6in ['a'..'z','z'..'a'])and (FileContents[i4+7in ['a'..'z','z'..'a'])and (FileContents[i4+8in ['A'..'Z','Z'..'A']))then
                    begin

                        gross := true;
                        StrassenTeil2 := Copy(FileContents,i4,(i4+8) - (i4));
                        Delete(FileContents,i4,(i4+8) - (i4));
                   end;
              end;


              if gross then begin

                   if (FileContents[i4+1in [' '])and (FileContents[i4+2in ['a'..'z','z'..'a','.','9'..'0','0'..'9']) then
                        begin
                         insert(StrassenTeil2,FileContents,i4+2);
                         gross := false;
                   end;



                end;//gross       // verbindet zwei strings

      end;

Vielen Dank

Moderiert von user profile iconNarses: Code- durch Delphi-Tags ersetzt
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 09.06.09 15:34 
Hey!
Ein paar Verbesserungsvorschläge:
Falsch: if gross = false then
Richtig if not gross then
Weshalb das so ist, findest du hier im Forum.

Was mir als zweites auffällt ist, dass du auf Buchstaben A bis Z und Z bis A prüfst. Wo liegt denn da bitte der Unterschied? :gruebel:

Grüße,
Marc.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 09.06.09 16:40 
Hallo,

ob das gut geht :gruebel:
Hab den Code mal etwas übersichtlicher formatiert und mit Delphi-Codes versehen.
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
gross := false;
for z := 0 to length(FileContents) do //ein String beginnt mit Index 1
  begin
  if gross = false then 
    begin
    if ((FileContents[z] in ['A'..'Z']) and 
        (FileContents[z+1in ['a'..'z']) and //bei den letzten Schleifendurchläufen
        (FileContents[z+2in ['a'..'z']) and //greift Du über den String hinnaus
        (FileContents[z+3in ['a'..'z']) and 
        (FileContents[z+4in ['a'..'z']) and 
        (FileContents[z+5in ['a'..'z']) and 
        (FileContents[z+6in ['a'..'z']) and 
        (FileContents[z+7in ['a'..'z']) and 
        (FileContents[z+8in ['A'..'Z'])) then
       begin 
       gross := true;
       //(z+8) - (z)  ist immer 8, also Ergebnisstring hat immer 8 Zeichen
       StrassenTeil2 := Copy(FileContents,z,(z+8) - (z));
       Delete(FileContents,z,(z+8) - (z));
       end;
    end;
  // wird nur ausgeführt wenn irgendwo im String
  // hinter einem Großbuchstaben 7 Kleinbuchstaben folgen
  // und danach ein Großbuchstabe
  if gross then 
    begin
    if (FileContents[z+1] = ' 'and (FileContents[z+2in ['a'..'z','.','0'..'9']) then
      begin
      insert(StrassenTeil2,FileContents,z+2);
      gross := false;
      end;
    end;//gross       // verbindet zwei strings
  end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
basner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Di 09.06.09 16:53 
Hallo und Danke.

Ja das Script war so gemeint. Da der Zerlegt Teil immer mit einem Großbuchstaben und 7 Kleinbuchstaben anfängt.

Das mit der 1 habe ich glatt übersehen. ;-)

Das zweite im [] sollte sich auf die Umlaute beziehen war noch nicht ganz fertig. Wollte nur zeigen das es gelöst ist.

Aber vielen Dank für die nützlichen Tips. Echt tolles Forum.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 09.06.09 17:16 
Hallo,

dann würde ich aber noch die Schleife nur bis Length(s) - 8 laufen lassen.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )