Find string after other string
#1

Example: My nick is So_Ugly.

How do I find "Ugly" string after _?

I tryed:

Code:
new Symbol = strfind(name, "_", true);
new tmp[24] = strtok(name, Symbol);
SendClientMessage(playerid, RED, tmp);
Didn't worked....
Reply
#2

pawn Code:
new last[20]; sscanf(name, "'_'s[20]", last);
Reply
#3

Quote:

CMD:lastname(playerid, params[])
{
new name[24];
GetPlayerName(playerid, name, 24);
new last[20]; sscanf(name, "'_'s[20]", last);
SendClientMessage(playerid, RED, last);
return 1;
}

Sends empty client message...
Reply
#4

You can do stuff like
strcat(destination, source[starting_index])
So:
pawn Code:
CMD:lastname(playerid, params[])
{
    new szName[24], szLastName[24];
    GetPlayerName(playerid, szName, sizeof(szName));
    strcat(szLastName, szName[strfind(szName, "_", true) + 1]);
    SendClientMessage(playerid, RED, szLastName);
    return 1;
}
This means you don't need to get the sscanf plugin in case you don't yet have it.

Edit
Although, I just ran some tests, and using sscanf is quite a bit faster in such case.
pawn Code:
CMD:lastname(playerid, params[])
{
    new szName[24], szLastName[24];
    GetPlayerName(playerid, szName, sizeof(szName));
    sscanf(szName, "'_'s[20]", szLastName);
    SendClientMessage(playerid, RED, szLastName);
    return 1;
}
Reply
#5

With strcat works, but with sscanf it sends empty client message... Of course, thanks, but it will be better with sscanf...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)