Szerző Téma: RemoveHexColorFromString  (Megtekintve 1916 alkalommal)

Nem elérhető Sramm

  • 596
    • Profil megtekintése
RemoveHexColorFromString
« Dátum: 2013. Február 14. - 18:27:13 »
0
A kód arra jó, hogy egy üzenetbõl eltávolíthatjuk vele az összes hex kódot.
Példa:
 
{ffffff}Ez egy fehér hex kódos szöveg.

 
A függvény lefutása után:
 
Ez egy fehér hex kódos szöveg.

 



Példaszkript:





// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT
#include <a_samp>
 
stock RemoveHexColorFromString(string[],startpos = 0)
{
    new
        pos[2];
    pos[0] = strfind(string,\"{\",true,startpos);
pos[1] = strfind(string,\"}\",true,startpos);
while(pos[0]+7 == pos[1])
{
        strdel(string, pos[0], pos[1]+1);
        pos[0] = strfind(string,\"{\",true,startpos);
pos[1] = strfind(string,\"}\",true,startpos);
}
return 1;
}
main() {}
public OnGameModeInit()
{
new str[] = \"Ez a fehér hex: {ffffff}\";
print(str);
RemoveHexColorFromString(str);
print(str);
new str2[] = \"{ffffff}Ez a fehér hex: {ffffff}-< Meg ez is.{fffffff}\";
print(str2);
RemoveHexColorFromString(str2);
print(str2);
new str3[] = \"{ffffff}Ez a startpos teszt: {ffffff}-< Meg ez is.{fffffff}\";
print(str3);
RemoveHexColorFromString(str3,8);
print(str3);
return 1;
}

 
 


Kép:
\"a1_2013_2_14_6kscz2r2z8.png\"


A kód:
 
stock RemoveHexColorFromString(string[],startpos = 0)
{
    new
        pos[2];
    pos[0] = strfind(string,\"{\",true,startpos);
pos[1] = strfind(string,\"}\",true,startpos);
while(pos[0]+7 == pos[1])
{
        strdel(string, pos[0], pos[1]+1);
        pos[0] = strfind(string,\"{\",true,startpos);
pos[1] = strfind(string,\"}\",true,startpos);
}
return 1;
}
« Utoljára szerkesztve: 2013. Február 14. - 19:08:41 írta Sramm »

Nem elérhető Live

  • 507
    • Profil megtekintése
RemoveHexColorFromString
« Válasz #1 Dátum: 2013. Február 14. - 18:32:34 »
0
Szép munka!

RemoveHexColorFromString
« Válasz #2 Dátum: 2013. Február 14. - 18:35:40 »
0
Nem rossz, bár szerintem \"do while\" ciklussal egyszerûbben meglehet írni.
Edit:
Még jobban megnézve a a for ciklusban lévõ \"i\" változót nem használod szinte semmire.
Az strfind-nél is kihasználhatnád a keresési pozíció megadásának lehetõségét.
És talán a ciklus feltételnek azt is használhatnád hogy ha az strfind talál \"{\" kapcsos zárójelet, akkor nem kellene végig futtatni egy teljes ciklus sorozatot a karakterek számával.
« Utoljára szerkesztve: 2013. Február 14. - 18:41:04 írta ɐʞzssǝlosz »

Nem elérhető Sramm

  • 596
    • Profil megtekintése
RemoveHexColorFromString
« Válasz #3 Dátum: 2013. Február 14. - 18:38:08 »
0
Idézetet írta: ɐʞzssǝlosz date=1360863340\" data-ipsquote-contentapp=\"forums\" data-ipsquote-contenttype=\"forums\" data-ipsquote-contentid=\"33789\" data-ipsquote-contentclass=\"forums_Topic
Nem rossz, bár szerintem \"do while\" ciklussal egyszerûbben meglehet írni.
 
Ha sokan panaszkodnak rá, átírom, mondjuk szerintem  olyan nagy szintû eltérés nincs :)
Köszi nektek :)

RemoveHexColorFromString
« Válasz #4 Dátum: 2013. Február 14. - 18:42:18 »
0
Írtam pár tanácsot feljebb, olvasd el, legalább lesz egy kis idõ töltésed estére a kód átírásával ha megfogadod azokat.  :D :D

Nem elérhető Sramm

  • 596
    • Profil megtekintése
RemoveHexColorFromString
« Válasz #5 Dátum: 2013. Február 14. - 19:07:49 »
0
Kész. Remélem így gondoltad :D
(Ennél azért nehezebb kell, hogy sok idõt töltsek vele el :D)

Nem elérhető DrAkE

  • 2078
    • Profil megtekintése
RemoveHexColorFromString
« Válasz #6 Dátum: 2013. Február 14. - 19:52:00 »
+1
Ha nem gond, leegyszerûsítettem:
 

stock RemoveHexColorFromString(string[], startpos = 0)
{
new pos[2];
while(((pos[0] = strfind(string, \"{\", .pos = startpos)) + 7) == (pos[1] = strfind(string, \"}\", .pos = startpos)))
strdel(string, pos[0], pos[1]+1);
return 1;
}

RemoveHexColorFromString
« Válasz #7 Dátum: 2013. Február 14. - 19:53:09 »
0
Idézetet írta: Sramm date=1360865269\" data-ipsquote-contentapp=\"forums\" data-ipsquote-contenttype=\"forums\" data-ipsquote-contentid=\"33789\" data-ipsquote-contentclass=\"forums_Topic
Kész. Remélem így gondoltad :D
(Ennél azért nehezebb kell, hogy sok idõt töltsek vele el :D)
 
Nem.
Hanem valami ilyesmire gondoltam:  :D
 

Ha nem gond, leegyszerûsítettem:
 

stock RemoveHexColorFromString(string[], startpos = 0)
{
new pos[2];
while(((pos[0] = strfind(string, \"{\", .pos = startpos)) + 7) == (pos[1] = strfind(string, \"}\", .pos = startpos)))
strdel(string, pos[0], pos[1]+1);
return 1;
}

 

[/quote]

Nem elérhető Sramm

  • 596
    • Profil megtekintése
RemoveHexColorFromString
« Válasz #8 Dátum: 2013. Február 14. - 19:55:14 »
0
Idézetet írta: ɐʞzssǝlosz date=1360867989\" data-ipsquote-contentapp=\"forums\" data-ipsquote-contenttype=\"forums\" data-ipsquote-contentid=\"33789\" data-ipsquote-contentclass=\"forums_Topic


Kész. Remélem így gondoltad :D
(Ennél azért nehezebb kell, hogy sok idõt töltsek vele el :D)
 
Nem.
Hanem valami ilyesmire gondoltam:  :D
 

Ha nem gond, leegyszerûsítettem:
 

stock RemoveHexColorFromString(string[], startpos = 0)
{
new pos[2];
while(((pos[0] = strfind(string, \"{\", .pos = startpos)) + 7) == (pos[1] = strfind(string, \"}\", .pos = startpos)))
strdel(string, pos[0], pos[1]+1);
return 1;
}

 

[/quote]
 
[/quote]
A lényege ugyan az, csak egy sorba be lett sûrítve :D
 

Ha nem gond, leegyszerûsítettem:
 

stock RemoveHexColorFromString(string[], startpos = 0)
{
new pos[2];
while(((pos[0] = strfind(string, \"{\", .pos = startpos)) + 7) == (pos[1] = strfind(string, \"}\", .pos = startpos)))
strdel(string, pos[0], pos[1]+1);
return 1;
}

 

[/quote]
Köszi, kinek mi átláthatóbb :)

RemoveHexColorFromString
« Válasz #9 Dátum: 2013. Február 14. - 19:58:33 »
0
@DrAkE
Persze mûködõ képes változatra gondoltam.  :angel:
Edit:
Ennél:
 
\"{ffffff}Ez a fehér hex: {ffffff}-< Meg ez is.{fffffff}\";[/quote]
Az utolsó {ffffff}-t nem törli.
« Utoljára szerkesztve: 2013. Február 14. - 20:49:50 írta ɐʞzssǝlosz »

Nem elérhető Sramm

  • 596
    • Profil megtekintése
RemoveHexColorFromString
« Válasz #10 Dátum: 2013. Február 14. - 20:02:06 »
0
Idézetet írta: ɐʞzssǝlosz date=1360868313\" data-ipsquote-contentapp=\"forums\" data-ipsquote-contenttype=\"forums\" data-ipsquote-contentid=\"33789\" data-ipsquote-contentclass=\"forums_Topic
@DrAkE
Persze mûködõ képes változatra gondoltam.  :angel:
Edit:
Ennél:
 
\"{ffffff}Ez a fehér hex: {ffffff}-< Meg ez is.{fffffff}\";
Az utolsó {ffffff}-t nem törli.
 
[/quote]
Direkt, ugyanis az nem mûködõképes Hex kód. (7 betû van 6 helyet)

RemoveHexColorFromString
« Válasz #11 Dátum: 2013. Február 14. - 20:36:00 »
+2
Köszi, figyelmetlen voltam nem vettem észre.
Sok fffffffff. :D
Lehet nem kellene közben skypolni tévézni meg vacsorázni, de a lényeg a lényeg írtam egy változatot én is, nagyon tesztelni nem volt idõm.
Íme:
 
stock 
RemoveHexColorFromString(str[], start = 0)
{
new
i = start;
while(str)
{
if(str == \'{\' && str[i + 7] == \'}\')
{
   strdel(str, i, i + 8);
}
i++;
}
return 1;
}

 


Edit1:
Itt egy veszélyesebb változat, csak így estére unalomûzés végett:  :)
 
stock 
RemoveHexColorFromString(str[], i = 0)
{
while(str) if(str[i++] == \'{\' && str[i + 6] == \'}\') strdel(str, i - 1, i + 7);
}

 


Edit2:
És akkor ezzel a verzióval azt hiszem be is fejeztem:  (strdel nélkül) >:D
 
stock 
RemoveHexColorFromString(str[], i = 0)
{
new
pos,
lenght = strlen(str);
while(i + pos < lenght)
{
if(str[i + pos] == \'{\' && str[i + pos + 7] == \'}\') pos += 8;
str = str[i + pos];
i++;
}
str = EOS;
}
« Utoljára szerkesztve: 2013. Február 15. - 01:25:06 írta ɐʞzssǝlosz »

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal