Raised This Month: $ Target: $400
 0% 

[SOLVED]Extractstr stock


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
purple_pixie
Veteran Member
Join Date: Jun 2007
Location: Winchester, England
Old 11-28-2007 , 08:24   Re: Extractstr stock
Reply With Quote #2

Don't quite have time to read all that, but is it anything like this stock?

Code:
stock str_piece(const input[],output[][],outputsize,piecelen,&token='|') {     // takes the string input and puts it into output[]     // each level of output is a "piece" of input, delimeted by token.     // return value is the number of pieces.     // outputsize is the max number of levels to fill ( sizeof output )     // piecelen is the max length of a piece ( sizeof output[] - 1 )     // e.g.       // new array[3][4];     // str_piece("abcdef|ghijkl|mnopqr|stuvw|xyz",array,sizeof array,sizeof array[] - 1,'|')     // returns 3.     // and sets the array as:     // array[0]="abc"     // array[1]="ghi"     // array[2]="mno"     // ( only 3 pieces can be returned, with a max length of 3 )         new i=-1,pieces,len=-1 ;     while ( input[++i] != 0 )     {         if ( input[i] != token )         {             if ( ++len < piecelen )                 output[pieces][len] = input[i] ;         }         else         {             output[pieces++][++len] = 0 ;             len = -1 ;             if ( pieces == outputsize )                 return pieces ;         }     }     return pieces + 1; }

(From pixie_stocks, naturally)

EDIT: OK, similar but not quite the same.
Can't see the problem with yours ... does this work?
Code:
stock extractstr(source[],start,end,output[128]) {     new maxlength = strlen(source)     new len     new bool:started     for ( new i ; i < maxlength ; i ++ )     {         if ( started )         {             if ( source[i] == end )             {                 output[len] = 0 ;                 break ;             }             output[len++]=source[i] ;             if ( len == sizeof output )             {                 output[len] = 0 ;                 break ;             }             continue ;         }         if ( source[i] == start )             started = true ;     }     trim(output) ;     return ; }

Last edited by purple_pixie; 11-28-2007 at 08:33.
purple_pixie is offline
 



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:11.


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