username splitting sscanf -
Zorono - 24.11.2017
Hello everybody, please could anyone help me with Word splitting using sscanf for example @Kalcor#2006
i wants to spllit this word and get the username without the @ and the Discriminator without the dash
i have no idea how to do this...
Re: username splitting sscanf -
pollo97 - 24.11.2017
Is that you were looking for?
Код:
new startpos = strfind("@Kalcor#2006","@");
if(startpos==-1) SendClientMessage(playerid,-1,"@ not found");
new endpos = strfind("@Kalcor#2006","#");
if(endpos==-1) SendClientMessage(playerid,-1,"# not found");
new string[64];
new discriminator[16];
strmid(string,"@Kalcor#2006",startpos,endpos);
strmid(discriminator,"@Kalcor#2006",endpos,strlen("@Kalcor#2006"));
Re: username splitting sscanf -
Zorono - 24.11.2017
Quote:
Originally Posted by pollo97
Is that you were looking for?
Код:
new startpos = strfind("@Kalcor#2006","@");
if(startpos==-1) SendClientMessage(playerid,-1,"@ not found");
new endpos = strfind("@Kalcor#2006","#");
if(endpos==-1) SendClientMessage(playerid,-1,"# not found");
new string[64];
new discriminator[16];
strmid(string,"@Kalcor#2006",startpos,endpos);
strmid(discriminator,"@Kalcor#2006",endpos,strlen("@Kalcor#2006"));
|
Thanks @pollo97 for your great help
Yes, thats what I am looking for...
+repped
Re: username splitting sscanf -
SyS - 24.11.2017
using sscanf....
PHP код:
new name[]="@Kalcor#2006",updated_name[10];
sscanf(name,"P<@#>{s[10]}s[10]{s[10]}",updated_name);
Re: username splitting sscanf -
Zorono - 24.11.2017
Quote:
Originally Posted by SyS
using sscanf....
PHP код:
new name[]="@Kalcor#2006",updated_name[10];
sscanf(name,"P<@#>{s[10]}s[10]{s[10]}",updated_name);
|
Thanks @Sys for your help
This one is great but thats not what i mean 60% it spllits those symbols and then adds then in the same variable (i need each one on an variable as @poll97 did using strmid) but anyway thanks alot sir
Re: username splitting sscanf -
SyS - 24.11.2017
Quote:
Originally Posted by pollo97
Is that you were looking for?
Код:
new startpos = strfind("@Kalcor#2006","@");
if(startpos==-1) SendClientMessage(playerid,-1,"@ not found");
new endpos = strfind("@Kalcor#2006","#");
if(endpos==-1) SendClientMessage(playerid,-1,"# not found");
new string[64];
new discriminator[16];
strmid(string,"@Kalcor#2006",startpos,endpos);
strmid(discriminator,"@Kalcor#2006",endpos,strlen("@Kalcor#2006"));
|
strmid should extract from start+1 on first and endpos+1 in second to get string without "@" or "#"
your code now provides @Kalcor and #2006
Quote:
Originally Posted by Zorono
Thanks @Sys for your help
This one is great but thats not what i mean 60% it spllits those symbols and then adds then in the same variable (i need each one on an variable as @poll97 did using strmid) but anyway thanks alot sir
|
if you want the discriminator just unquiet the third specifier
PHP код:
new name[]="@Kalcor#2006",updated_name[10],discriminator[10];
sscanf(name,"P<@#>{s[10]}s[10]s[10]",updated_name,discriminator);
Re: username splitting sscanf -
GhostHacker9 - 24.11.2017
Quote:
Originally Posted by Zorono
Thanks @Sys for your help
This one is great but thats not what i mean 60% it spllits those symbols and then adds then in the same variable (i need each one on an variable as @poll97 did using strmid) but anyway thanks alot sir
|
pollo97's code wont give you the output that you want (read sys' reply) and is slower as compared to sscanf
Re: username splitting sscanf -
ThePhenix - 24.11.2017
You could so something like this:
PHP код:
new input_string[] = "@TestName#848913";
new username[64];
new discriminator;
new len = strlen(input_string);
for(new i = len; i--; )
{
if(input_string[i] == '#')
{
input_string[i] = ' ';
break;
}
}
if(!sscanf(input_string, "'@'s[64]d", username,discriminator))
{
//do something with username and discriminator
printf("Username: %s | Discriminator: %d ", username, discriminator);
}
Outputs:
Код:
Username: TestName | Discriminator: 848913
Re: username splitting sscanf -
Meller - 24.11.2017
Quote:
Originally Posted by ThePhenix
You could so something like this:
PHP код:
new input_string[] = "@TestName#848913";
new username[64];
new discriminator;
new len = strlen(input_string);
for(new i = len; i--; )
{
if(input_string[i] == '#')
{
input_string[i] = ' ';
break;
}
}
if(!sscanf(input_string, "'@'s[64]d", username,discriminator))
{
//do something with username and discriminator
printf("Username: %s | Discriminator: %d ", username, discriminator);
}
Outputs:
Код:
Username: TestName | Discriminator: 848913
|
What if the name is hello121312312 and the disc. is 9999?
mhm.
Re: username splitting sscanf -
Zorono - 25.11.2017
Quote:
Originally Posted by SyS
strmid should extract from start+1 on first and endpos+1 in second to get string without "@" or "#"
your code now provides @Kalcor and #2006
if you want the discriminator just unquiet the third specifier
PHP код:
new name[]="@Kalcor#2006",updated_name[10],discriminator[10];
sscanf(name,"P<@#>{s[10]}s[10]s[10]",updated_name,discriminator);
|
Thanks @SyS for your help alot but could you please explain for me your sscanf format ("P<@#>{s[10]}s[10]s[10]") and how do you spllit the @username#disc with this Specifiers ?? So i might do it next time by myself...
+repped
Quote:
Originally Posted by ThePhenix
You could so something like this:
PHP код:
new input_string[] = "@TestName#848913";
new username[64];
new discriminator;
new len = strlen(input_string);
for(new i = len; i--; )
{
if(input_string[i] == '#')
{
input_string[i] = ' ';
break;
}
}
if(!sscanf(input_string, "'@'s[64]d", username,discriminator))
{
//do something with username and discriminator
printf("Username: %s | Discriminator: %d ", username, discriminator);
}
Outputs:
Код:
Username: TestName | Discriminator: 848913
|
Thanks @ThePhenix alot for your help
Note: 35 cells is much enough as a username length, but anyway thanks sir
+repped