Raised This Month: $32 Target: $400
 8% 

[USEFUL FUNCTION] StrToken


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
API
Veteran Member
Join Date: May 2006
Old 05-10-2007 , 19:15   [USEFUL FUNCTION] StrToken
Reply With Quote #1

This is an easy way to token for a group secluded by whitespaces.
Example:
StrToken("Hello, this is a test.",3,out,24);
out will end up being "is".

Code:
public OnPluginStart()
{
    new String:test[]="Hello, this is a test string.";
    new String:out[]="";
    StrToken(test,5,out,192);
    PrintToServer("%s",out);
}

stock StrToken(const String:inputstr[],tokennum,String:outputstr[],maxlen)
{
    new String:buf[maxlen+1];
    new cur_idx;
    new idx;
    new curind;
    idx=StrBreak(inputstr,buf,maxlen);
    if(tokennum==1)
    {
        strcopy(outputstr,maxlen,buf);
        return;
    }
    curind=1;
    while (idx!=-1)
    {
        cur_idx+=idx;
        idx=StrBreak(inputstr[cur_idx],buf,maxlen);
        curind++;
        if(tokennum==curind)
        {
            strcopy(outputstr,maxlen,buf);
            break;
        }
    }
}

Last edited by API; 06-26-2007 at 01:48. Reason: more optimized and better method for strsize
API is offline
Send a message via AIM to API
API
Veteran Member
Join Date: May 2006
Old 05-10-2007 , 20:12   Re: [USEFUL FUNCTION] StrToken
Reply With Quote #2

Updated, see edit reason.
API is offline
Send a message via AIM to API
sskillz
Member
Join Date: Apr 2005
Old 05-12-2007 , 09:35   Re: [USEFUL FUNCTION] StrToken
Reply With Quote #3

I have used functions that deal with strings toknes in mIrc script and they are vary useful. Try add more function that will deal with tokens like:
a function to remove a token from a string (remove N token found matching something..), a function that will count how many tokens in a string, replace a token in a string, find the postion of a tokken in a string, check if a token is in a string, function that adds a token to a string and token shotring function.
sskillz is offline
API
Veteran Member
Join Date: May 2006
Old 06-26-2007 , 01:49   Re: [USEFUL FUNCTION] StrToken
Reply With Quote #4

URGENT FUNCTION UPDATE! FIXES CRASH BUG!
__________________
API is offline
Send a message via AIM to API
Reply



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

Forum Jump


All times are GMT -4. The time now is 15:41.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode