username splitting sscanf
#1

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...
Reply
#2

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"));
Reply
#3

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
Reply
#4

using sscanf....
PHP код:
new name[]="@Kalcor#2006",updated_name[10];
sscanf(name,"P<@#>{s[10]}s[10]{s[10]}",updated_name); 
Reply
#5

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
Reply
#6

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); 
Reply
#7

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
Reply
#8

You could so something like this:

PHP код:
new input_string[]  =     "@TestName#848913";
    new 
username[64];
    new 
discriminator;
    new 
len strlen(input_string);
    for(new 
leni--; )
    {
        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 "usernamediscriminator);
    } 
Outputs:

Код:
Username: TestName | Discriminator: 848913
Reply
#9

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 
leni--; )
    {
        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 "usernamediscriminator);
    } 
Outputs:

Код:
Username: TestName | Discriminator: 848913
What if the name is hello121312312 and the disc. is 9999?


mhm.
Reply
#10

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 
leni--; )
    {
        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 "usernamediscriminator);
    } 
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)