SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 02/04/2012, 11:20 AM   #1
!LukniS!
Little Clucker
 
Join Date: Dec 2011
Posts: 25
Reputation: 4
Default Find string after other string

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....
!LukniS! is offline   Reply With Quote
Old 02/04/2012, 11:23 AM   #2
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,067
Reputation: 2660
Default Re: Find string after other string

pawn Code:
new last[20]; sscanf(name, "'_'s[20]", last);
__________________
Vince is offline   Reply With Quote
Old 02/04/2012, 11:31 AM   #3
!LukniS!
Little Clucker
 
Join Date: Dec 2011
Posts: 25
Reputation: 4
Default Re: Find string after other string

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...
!LukniS! is offline   Reply With Quote
Old 02/04/2012, 11:43 AM   #4
AndreT
Gangsta
 
AndreT's Avatar
 
Join Date: Jul 2011
Posts: 966
Reputation: 414
Default Re: Find string after other string

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;
}

Last edited by AndreT; 02/04/2012 at 11:53 AM. Reason: Ran a test in loop with 100000 iterations and sscanf is faster than my method.
AndreT is offline   Reply With Quote
Old 02/04/2012, 12:15 PM   #5
!LukniS!
Little Clucker
 
Join Date: Dec 2011
Posts: 25
Reputation: 4
Default Re: Find string after other string

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
input line too long (after substitutions) - invalid string (possibly non-terminated string) MahmutBey Help Archive 6 10/03/2011 01:39 PM
Loading string from a file and inserting it into other string Ivan_Pantovic Help Archive 0 06/02/2011 07:22 PM
Find string in array clavador Help Archive 5 05/06/2010 02:25 PM
Find a string with brackets inside.... Trooper[Y] Help Archive 2 30/05/2010 02:47 PM


All times are GMT. The time now is 06:48 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.