nikitasicek 0 Odesláno: 18. Květen, 2014 Share Odesláno: 18. Květen, 2014 Zdravím, Potřeboval bych poradit, když mám string třeba: "blah,blah" Ale není daný kolik těch "blah" tam bude, někdy tam můžou být 2, někdy 10. A já potřebuju dostat z toho stringu oddělenýho "," každý to blah a uložit to jako array třeba arr[1] bude jedno blah, arr[2] druhý atd... Zkoušel jsem tohle: new arr[3]; sscanf("Hello,Hi", "p<,>a<s[20]>[3]", arr); print(arr[1]); Ale vrací to: "ello,Hi" Díky za pomoc. Link to comment Share on other sites More sharing options...
0 ATomas 291 Odesláno: 18. Květen, 2014 Share Odesláno: 18. Květen, 2014 new str[][];//nastav si, prvni je pocet stringu a druhy je velikost stringu new string[] = "ahoj,jak,se,mas?"; new pos; for(new i;i<sizeof(str) && pos > -1;i++) { new pos2 = chrfind(',',string,pos+1); format(str[i],pos2+1,string[pos+1]); pos = pos2; } takto nejak ? Link to comment Share on other sites More sharing options...
0 nikitasicek 0 Odesláno: 18. Květen, 2014 Author Share Odesláno: 18. Květen, 2014 new str[][];//nastav si, prvni je pocet stringu a druhy je velikost stringu new string[] = "ahoj,jak,se,mas?"; new pos; for(new i;i<sizeof(str) && pos > -1;i++) { new pos2 = chrfind(',',string,pos); format(str[i],pos2+1,string[pos+1]); pos = pos2; } takto nejak ? hoj, jak, jak, jak, Zkoušel jsem to i poupravit dle sebe, jak jsem si myslel, že by to mohlo jít, ale pořád to vrací to stejný. P musí byť veľké. // [10] = veľkosť poľa // [100] = dĺžka stringu // <s[100]> = o aké pole sa jedná (strig = 's + veľkosť', integer = i, float = f) // a = znak toho, že sa bude rozdeľovať do arrayu // <,> = znak rozdelenia // P = rozdelenie stringu do poľa sscanf("Hello,Hi", "P<,>a<s[100]>[10]", array); a pole musí byť logicky 2D new array[3][100]; A tohle mi zase vrací celý ten string, tedy "Hello,Hi" z toho normálně vypadne. Sedím nad tím celý odpoledne a furt ne a ne to fungovat. Jinak pokud to pomůže, snažím se to použít na získání seznamu produktů nemovitosti, který mám v souboru jako "Produkty=Infernus,Turismo" a uložit si je pro každou nemovitost, dané produkty. Pokud je nějaká efektivnější metoda, tak si ji taky rád přečtu . Link to comment Share on other sites More sharing options...
0 nikitasicek 0 Odesláno: 18. Květen, 2014 Author Share Odesláno: 18. Květen, 2014 Takže asi nepoužívaš pluginovú verziu sscanf. Lebo teraz som to testoval presne ten tvoj kód a všetko fungovalo na 100%. http://prntscr.com/3kfg0m code new array[10][100]; sscanf("Hello,Hi,pridal,som,novy,string", "P<,>a<s[100]>[10]", array); printf("%s|%s|%s|%s|%s|%s",array[0],array[1],array[2],array[3],array[4],array[5]); Plugin http://forum.sa-mp.com/showthread.php?t=120356 Updatoval jsem sscanf, zkopíroval, vložil stejný kód co jsi poslal a výsledek: new array[10][100]; sscanf("Hello,Hi,pridal,som,novy,string", "P<,>a<s[100]>[10]", array); printf("%s|%s|%s|%s|%s|%s",array[0],array[1],array[2],array[3],array[4],array[5]); Celkem záhada... Link to comment Share on other sites More sharing options...
0 ATomas 291 Odesláno: 19. Květen, 2014 Share Odesláno: 19. Květen, 2014 new str[][];//nastav si, prvni je pocet stringu a druhy je velikost stringu new string[] = "ahoj,jak,se,mas?"; new pos; for(new i;i<sizeof(str) && pos > -1;i++) { new pos2 = chrfind(',',string,pos+1); format(str[i],pos2+1,string[pos+1]); pos = pos2; } Takto by to uz melo jit. Link to comment Share on other sites More sharing options...
0 nikitasicek 0 Odesláno: 20. Květen, 2014 Author Share Odesláno: 20. Květen, 2014 public OnGameModeInit() { SetGameModeText("Test"); AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); SetTimer("carStatusUpdate",300,1); SetTimer("benzinUpdate",2000,1); for(new i = 1;i<MAX_VEHICLES;i++) { VehicleFuel[i] = 10.0 + random(10); } gettime(Hour, Minute, Second); Second = 0; SetTimer("Tick",1000,1); nemovitostiCreate(); //----- Textdraw1 = TextDrawCreate(546.000000, 24.000000, "_"); TextDrawBackgroundColor(Textdraw1, 255); TextDrawFont(Textdraw1, 1); TextDrawLetterSize(Textdraw1, 0.240000, 1.000000); TextDrawColor(Textdraw1, -1); TextDrawSetOutline(Textdraw1, 1); TextDrawSetProportional(Textdraw1, 1); TextDrawSetSelectable(Textdraw1, 0); //----- Textdraw3 = TextDrawCreate(547.000000, 34.000000, "_"); TextDrawBackgroundColor(Textdraw3, 255); TextDrawFont(Textdraw3, 3); TextDrawLetterSize(Textdraw3, 0.539999, 2.399999); TextDrawColor(Textdraw3, -1); TextDrawSetOutline(Textdraw3, 1); TextDrawSetProportional(Textdraw3, 1); TextDrawSetSelectable(Textdraw3, 0); //----- Textdraw4 = TextDrawCreate(148.000000, 339.000000, "ads da d a das d a da d adadas"); TextDrawBackgroundColor(Textdraw4, 255); TextDrawFont(Textdraw4, 3); TextDrawLetterSize(Textdraw4, 0.500000, 2.500000); TextDrawColor(Textdraw4, -1); TextDrawSetOutline(Textdraw4, 1); TextDrawSetProportional(Textdraw4, 1); TextDrawUseBox(Textdraw4, 1); TextDrawBoxColor(Textdraw4, -256); TextDrawTextSize(Textdraw4, 467.000000, 20.000000); TextDrawSetSelectable(Textdraw4, 0); sscanf("Hello,Hi,pridal,som,novy,string", "P<,>a<s[100]>[10]", array); printf("%s|%s|%s|%s|%s|%s",array[0],array[1],array[2],array[3],array[4],array[5]); } Tohle je celý. Furt netuším, čím to je. Link to comment Share on other sites More sharing options...
0 nikitasicek 0 Odesláno: 20. Květen, 2014 Author Share Odesláno: 20. Květen, 2014 new array[6][100]; Různě jsem ji zkoušel i upravovat ale taky nic, pořád stejný výsledek. Link to comment Share on other sites More sharing options...
0 nikitasicek 0 Odesláno: 20. Květen, 2014 Author Share Odesláno: 20. Květen, 2014 Pořád stejný. Zkusil jsem vytvořit i novej čistej mód a stejně to dělá pořád to samý, takže bude problem buď ve sscanf, pawnu nebo nevím. Nemůžeš mi někam reupnout ten Tvůj sscanf se kterým ti to jede? Link to comment Share on other sites More sharing options...
0 nikitasicek 0 Odesláno: 20. Květen, 2014 Author Share Odesláno: 20. Květen, 2014 Taky nepomáhá, no to mi řekni, co s tím... Link to comment Share on other sites More sharing options...
0 nikitasicek 0 Odesláno: 20. Květen, 2014 Author Share Odesláno: 20. Květen, 2014 Dávno jsem psal, y_less tam poslal odkaz na tu jeho wiki podle které jsem to dělal a to je tak vše. Link to comment Share on other sites More sharing options...
0 nikitasicek 0 Odesláno: 20. Květen, 2014 Author Share Odesláno: 20. Květen, 2014 Nejede, nemůžeš to hodit do novýho scriptu a poslat mi v zipu celej ten server ? Pak snad zjistíme čím to teda je. Nejde mi editovat příspěvek, tak snad omluvíte ten doublepost. Problém je vyřešen, mám nějakou chybnou konzoli ale když jsem to dal do SCM, tak to vrátilo vše v pořádku. Tohle jsem měl udělat už dřív, jsem blbec. Díky za snahu oboum. Link to comment Share on other sites More sharing options...
Dotaz
nikitasicek 0
Link to comment
Share on other sites
10 odpovědí na tuto otázku
Recommended Posts