Schön oder Mist ?



  • Ich habe dies in einer Schleife benutzt, um von [...] bis zum Ende zu lesen,
    ist das schön oder eher weniger ?

    Setup->Strings[i].SubString(Echar,1) != "\0"
    

    EDIT: Ganz nebenbei löst das ein Compiler Bug in 2009 aus, der mit //" zu lösen ist.
    er setzt ∞ oft } nach der Schleife



  • Setup->Strings[i].SubString(Echar,1) != "\0"
    

    Wenn das deine Abbruchbedingung ist, dann ist das unschön.
    wiso nicht:

    int iRow=0; // dein begin [...]
    
    for (iRow; iRow< Setup->Count; ++iRow) {
    
        Setup->Strings[iRow] //du was du willst mit den Zeilen 
    }
    


  • VergissEs schrieb:

    Wenn das deine Abbruchbedingung ist, dann ist das unschön.

    Ists nicht 🙂

    Sind mehrere Abragen im Code und je nachdem was zutrifft, wird der entsprechende Abschnitt einem String hinzugefügt, bis ein Zeichen kommt, aber am Ende kommt... das Ende. (Nullterminierung)



  • Zumindest könnte man das hier

    Setup->Strings[i].SubString(Echar,1) != "\0"
    

    durch das hier ersetzen

    Setup->Strings[i][Echar] != '\0'
    

    So eine Abfrage kommt mir aber auch komisch vor. Da kann man bestimmt den Algorithmus verbessern. 🙂



  • Wenn du meinst 😃

    TStringList* Setup = new TStringList;
    while (i < Setup->Count)
    {
    	i++;
    	int Echar = 0;
    	//Setup->Strings[i-1]
    	if (Setup->Strings[i-1][Echar] == 'X')
    	{
    		Echar+=2;
    		String X;
    		while (Setup->Strings[i-1].SubString(Echar,1) != "Y")
    		{
    			Echar++;
    			X += Setup->Strings[i-1].SubString(Echar,1);
    		}
    		X = X.SubString(0,X.Length()-1);
    		ShowMessage(X);
    	}
    	if (Setup->Strings[i-1][Echar] == 'Y')
    	{
    		Echar+=2;
    		String Y;
    		while (Setup->Strings[i-1].SubString(Echar,1) != "\0")
                   {
    			Echar++;
    			Y += Setup->Strings[i-1].SubString(Echar,1);
    		}
    		ShowMessage(Y);
    	}
    }
    

    (X: Y: geben mausklickpositionen an, die später simuliert werden, hier werden sie gelesen)
    Datei:

    ChampionName oder was anderes
    ClientPosition_X: 0 ClientPosition_Y: 0
    STANDART
    X: 805 Y: 618
    X: 805 Y: 618
    X: 805 Y: 618
    X: 805 Y: 618
    X: 1162 Y: 481
    X: 1156 Y: 393
    X: 1220 Y: 349
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339
    X: 1216 Y: 339

    EDIT : REFORMAT



  • Ich werf mal den Code ins rennen.

    #include <vector>
    #include <memory>
    
    	std::vector<TPoint> Points;
    	std::auto_ptr<TStringList> Setup(new TStringList());
    	Setup->LoadFromFile(DieDatei);
    
    	int XPos, YPos;
    	TPoint MyPoint;
    
    	for (int i=0; i < Setup->Count; i++) {
    
    		XPos = Setup->Strings[i].Pos("X:");
    		YPos = Setup->Strings[i].Pos("Y:");
    
    		if (XPos > 0 && YPos > 0) {
    
    			MyPoint.x = Trim(Setup->Strings[i].SubString(XPos+2, YPos-XPos-2)).ToIntDef(-1);
    			MyPoint.y = Trim(Setup->Strings[i].SubString(YPos+2, Setup->Strings[i].Length()-YPos-1)).ToIntDef(-1);
    
    			if (MyPoint.x != -1 && MyPoint.y != -1) Points.push_back( MyPoint );
    		}
    	}
    }
    


  • int posx,posy;
    int x,y;
    for(int i=0;i<Setup->Count;i++)
    {
    	posx=Setup->Strings[i].Pos("X: ");
    	posy=Setup->Strings[i].Pos("Y: ");
    	ShowMessage(Setup->Strings[i].SubString(posx+3,posy-posx-4));
    	ShowMessage(Setup->Strings[i].SubString(posy+3,Setup->Strings[i].Length()-posy-posx+1));
    }
    


  • berlinbär schrieb:

    int posx,posy;
    int x,y;
    for(int i=0;i<Setup->Count;i++)
    {
    	posx=Setup->Strings[i].Pos("X: ");
    	posy=Setup->Strings[i].Pos("Y: ");
    	ShowMessage(Setup->Strings[i].SubString(posx+3,posy-posx-4));
    	ShowMessage(Setup->Strings[i].SubString(posy+3,Setup->Strings[i].Length()-posy-posx+1));
    }
    

    Obacht geben da wird die Zeile

    ClientPosition_X: 0 ClientPosition_Y: 0
    

    auch mit angezeigt

    bzw. in

    ShowMessage(Setup->Strings[i].SubString(posy+3,Setup->Strings[i].Length()-posy-posx+1));
    

    -posy-posx+1 kann nicht stimmen



  • Wenn sich am Aufbau der Daten nichts ändert dann so:

    Setup->Delimiter=' ';
    Setup->LoadFromFile("liste.txt");
    Setup->DelimitedText = Setup->Text;
    for(int i=0;i<Setup->Count-1;i++)
    {
    	if(Setup->Strings [i]=="X:") ShowMessage("X:"+Setup->Strings[i+1]);
    	else if(Setup->Strings [i]=="Y:") ShowMessage("Y:"+Setup->Strings[i+1]);
    }
    

Anmelden zum Antworten