Find string after other string - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Find string after other string (
/showthread.php?tid=330728)
Find string after other string -
!LukniS! - 02.04.2012
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....
Re: Find string after other string -
Vince - 02.04.2012
pawn Code:
new last[20]; sscanf(name, "'_'s[20]", last);
Re: Find string after other string -
!LukniS! - 02.04.2012
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...
Re: Find string after other string -
AndreT - 02.04.2012
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;
}
Re: Find string after other string -
!LukniS! - 02.04.2012
With strcat works, but with sscanf it sends empty client message... Of course, thanks, but it will be better with sscanf...