Raised This Month: $ Target: $400
 0% 

parse string with delimeter


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 11-22-2010 , 13:37   Re: parse string with delimeter
Reply With Quote #1

Untested:
Code:
stock parsetok(const text[], token='', trimSpaces=0, ...)
{
	new argnum = numargs();
	if( argnum < 5 )
		return 0;

	new _text[512], _left[256], _len, _arg, _i;
	copy( _text, charsmax(_text), text );
	do
	{
		_len = min( charsmax(_left), getarg( 4 + (2*_arg) ) );
		strtok( _text, _left, _len, _text, charsmax(_text), token, trimSpaces );

		for( _i = 0; _i < _len && _left[_i] != '^0'; _i++ )
		{
			setarg( 3 + (2*_arg), _i, _left[_i] );
		}
		if( arg >= argnum )
			break;
		_arg++;
	}
	while( _text[0] != '^0' )

	return _arg;
}
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-22-2010 , 14:02   Re: parse string with delimeter
Reply With Quote #2

Quote:
Originally Posted by Emp` View Post
Untested:
Code:
stock parsetok(const text[], token='', trimSpaces=0, ...)
IIRC you cannot use '' for a character.
You must give a character or number.

EDIT:

Here's my version without limits within the function:
Code:
stock parsetok(const text[], token=' ', trimSpaces=0, ...) {     new iArgCount = numargs( );     if( iArgCount < 5 )     {         return 0;     }         new szFind[ 2 ];     szFind[ 0 ] = token;         new iTextLen = strlen( text );     new iStart, iStop;     new iArgStringIndex = 3;     new iArgLenIndex = 4;     new iParseCount;     new iArgLen;     new i;         while( iArgStringIndex < iArgCount && iArgLenIndex < iArgCount && iStart < iTextLen )     {         while( trimSpaces && text[ iStart ] == ' ' && iStart < iTextLen )         {             iStart++;         }                 iStop = contain( text[ iStart ], szFind ) + iStart;                 if( iStop < iStart )         {             iStop = iTextLen;         }                 iArgLen = getarg( iArgLenIndex );                 if( iArgLen > 0 )         {             for( i = 0; i < iArgLen; i++ )             {                 setarg( iArgStringIndex, i, text[ i + iStart ] );             }                         setarg( iArgStringIndex, iArgLen, EOS );         }                 iStart = iStop + 1;                 iArgStringIndex += 2;         iArgLenIndex += 2;         iParseCount++;     }         return iParseCount; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 11-23-2010 at 08:46.
Exolent[jNr] is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 11-23-2010 , 15:46   Re: parse string with delimeter
Reply With Quote #3

Quote:
Originally Posted by Exolent[jNr] View Post
IIRC you cannot use '' for a character.
You must give a character or number.
You're right, I looked at strtok on the funcwiki really quick and assumed it was ''.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
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 11:16.


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