Autor Beitrag
g1o2k4
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 493



BeitragVerfasst: Mo 09.04.07 17:20 
nabend

zerlege in einem projekt einen buchstaben text 'abcd' in zahlen. dabei hat jeder buchstabe mal 3 mal 4 mal 5 ziffern. die zahlen werden aneinander gereiht: '283 2918 34728 283' das leerzeichen soll dabei als trennzeichen dienen.
wie kann ich nun die zifferngruppen von dem restlichen stringtrennen ?
vielleicht mit nem beispiel ?

danke. grüße g1o
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Mo 09.04.07 17:24 
Geh den string Zeichen für Zeichen durch, ist das aktuelle Zeichen kein Leerzeichen fügst du es zu einem temporären string hinzu (tempstring:=tempstring+zeichen). ist das zeichen ein Leerzeichen speicherst du den tempstring irgendwo ab und leerst ihn dann, dann wird er wieder aufgefüllt bis zum nöchsten Leerzeichen...
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 09.04.07 17:28 
Schau mal in der Hilfe nach Pos, Copy und PosEx.

_________________
We are, we were and will not be.
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Mo 09.04.07 17:57 
ausblenden Delphi-Quelltext
1:
ExtractStrings([Trennzeichen], [Trennzeichen], PChar(DeinString), ZielStringListe);					


Beispiel:ExtractStrings([#32], [#32], PChar(a), sta);
g1o2k4 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 493



BeitragVerfasst: Mo 09.04.07 18:59 
Pos und Copy war genau das was ich brauchte ;)

für alle dies interessiert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
   for I := 0 to length(tempX) do      // Erklärung in Dokumentation.
    begin
      Pos1 := Pos(';',tempX);                      // Pos1: stelle des ersten ;
      if Pos1 > 0 then
      begin
        temp := copy(tempX,0,Pos1-1);              // string von anfang bis ; nach temp kopieren
        m := strtoint(temp);
        tempX := copy(tempX,Pos1+1,Length(TempX)); // neues tempX ohne ersten teil: von Pos1 bis ende kopieren

        j := XhochYmodZ(m, strtoint(ESchluesseld.Text), strtoint(ESchluesseln2.Text)); // (RSA Verfahren)
        temp := chr(j);
        MKlartext.Text := MKlartext.Text+temp;
      end

    else exit;

    end;
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Mo 09.04.07 20:55 
Ich finde Code immer sehr schlecht wartbar sobald Pos oder copy mit ins Spiel kommen.
Du kannst dir die entsprechende Lösung mit ExtractStrings ja mal ansehen. Ist kürzer und imho übersichtler so.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
begin
 sList:=TStringList.Create;
 ExtractStrings([#32], [#32], PChar(tempX), SList);
 for i:=0 to sList.Count-1 do
  MKlartext.Text:=MKlartext+Chr(XhochYmodZ(sList[i], strtoint(ESchluesseld.Text),strtoint(ESchluesseln2.Text)));
 sList.Free;
end;