Seperating name into 2 parts,
#1

Hey there, How would I seperate a name?
EXAMPLE:

Someone's name is John_Dalton

I want it to show on a passport like
Name: John
SurName: Dalton


How would I do this
Reply
#2

Somthing lie this....

pawn Код:
new string[MAX_PLAYER_NAME];
    GetPlayerName(playerid, string, MAX_PLAYER_NAME);
    new pName[25];
    strmid(pName, string, 0, strlen(string), MAX_PLAYER_NAME);
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if (pName[i] == '_') pName[i] = ' ';
    }
(Ripped from my script
Reply
#3

Well, I dont see how that will show the sur and first name seperatly
Reply
#4

Quote:
Originally Posted by IceCube!
Посмотреть сообщение
Somthing lie this....

pawn Код:
new string[MAX_PLAYER_NAME];
    GetPlayerName(playerid, string, MAX_PLAYER_NAME);
    new pName[25];
    strmid(pName, string, 0, strlen(string), MAX_PLAYER_NAME);
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if (pName[i] == '_') pName[i] = ' ';
    }
(Ripped from my script
That won't separate them into two separate strings.. that'll just take out the underscore.
If only we were also allowed to take rep...
Reply
#5

Thanks for editing your first post and making me look like a right dick!. and then replying mking me look like a dick! I'll reply when you feel you can stop making me look like a dick!
Reply
#6

What? The OP did not edit his first post; I saw the message before you replied, and it was the same.
Reply
#7

Quote:
Originally Posted by IceCube!
Посмотреть сообщение
Thanks for editing your first post and making me look like a right dick!. and then replying mking me look like a dick! I'll reply when you feel you can stop making me look like a dick!
lol?
I never editted it?-.-
Reply
#8

That should work:
pawn Код:
#include <a_samp>

new name[24],name2[24],surname[24];

public OnPlayerCommandText(playerid,cmdtext[])
{
    if(!strcmp(cmdtext,"/test"))
    {
        GetPlayerName(playerid, name, sizeof(name));
        for(new i = 0; i < strlen(name); i++)
        {
            if(name[i] == '_')
            {
                strmid(name2,name,0,i);
                strmid(surname,name,(i+1),strlen(name));
            }
        }
        format(name,sizeof(name),"%s",name2);
        SendClientMessage(playerid, -1, name);
        format(name,sizeof(name),"%s",surname);
        SendClientMessage(playerid, -1, name);
        return 1;
    }
    return 0;
}
Reply
#9

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
That should work:
pawn Код:
#include <a_samp>

new name[24],name2[24],surname[24];

public OnPlayerCommandText(playerid,cmdtext[])
{
    if(!strcmp(cmdtext,"/test"))
    {
        GetPlayerName(playerid, name, sizeof(name));
        for(new i = 0; i < strlen(name); i++)
        {
            if(name[i] == '_')
            {
                strmid(name2,name,0,i);
                strmid(surname,name,(i+1),strlen(name));
            }
        }
        format(name,sizeof(name),"%s",name2);
        SendClientMessage(playerid, -1, name);
        format(name,sizeof(name),"%s",surname);
        SendClientMessage(playerid, -1, name);
        return 1;
    }
    return 0;
}
thanks will try it out
Reply
#10

Quote:
Originally Posted by milanosie
Посмотреть сообщение
thanks will try it out
A fully working function for further usages: (tested)
pawn Код:
Seperate(src[], res_string1[], res_string2[])
{
    for(new i = 0; i < strlen(src);i++)
    {
        if(src[i] == '_')
        {
            strmid(res_string1,src,0,i,24);
            strmid(res_string2,src,(i+1),strlen(src),24);
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)