Raised This Month: $ Target: $400
 0% 

Parsing strings with variable length


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mlk27
Veteran Member
Join Date: May 2008
Old 11-04-2009 , 22:54   Parsing strings with variable length
Reply With Quote #1

Strings:

Quote:
"This is random username 10000"
"Second username 500"
"Ludwig Van Beethoven 70"
How do I parse each of them into 2 strings? The bolded texts are usernames and the numbers at the end are their score.
Mlk27 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-04-2009 , 23:00   Re: Parsing strings with variable length
Reply With Quote #2

Code:
new szString[ 96 ]; // contains the username and number new szName[ 64 ], szNumber[ 32 ]; new iLen = strlen( szString ); for( new iPos = iLen - 1; iPos >= 0; iPos-- )     if( szString[ iPos ] == ' ' ) {         copy( szName, iPos, szString );         copy( szNumber, ( iLen - iPos - 1 ), szString[ iPos + 1 ] );         break;     } } new iNumber = str_to_num( szNumber )
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-04-2009 , 23:53   Re: Parsing strings with variable length
Reply With Quote #3

Here's a way you can do it without using copy or the name & number string variables.
PHP Code:
new szString96 ] = "the user name 5000"
new 
iLen strlenszString ) , iPos;
    
for( 
iPos iLen 1iPos >= 0iPos-- )
{
    if( 
szStringiPos ] == ' ' 
    {
        
szStringiPos ] = EOS;
        break;
    }
}

server_print"^"%s^" ^"%s^"" szString szStringiPos ] ); 
__________________

Last edited by Bugsy; 11-04-2009 at 23:55.
Bugsy is offline
Mlk27
Veteran Member
Join Date: May 2008
Old 11-04-2009 , 23:20   Re: Parsing strings with variable length
Reply With Quote #4

Are there other faster ways to do this as it will be used in client_authorized or that code is already fast enough?
Mlk27 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-04-2009 , 23:41   Re: Parsing strings with variable length
Reply With Quote #5

Where are the strings coming from?
__________________
fysiks is offline
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 17:39.


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