This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Splitting a string, like PHP's explode()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
.Prometheus.
Member
Join Date: Sep 2004
Old 10-30-2004 , 09:08   Splitting a string, like PHP's explode()
Reply With Quote #1

Yes I looked at parse and strbreak, they don't seem to be what I want.

What I want is to get a string and split it into little strings every time it encounters a char such as "|". The PHP way:

$del_files_exploded = explode("|", $del_files);

This will delete | from the source and make $del_files into an array, so if the source was "abc.html|poo.txt|yayforme.php" it would make $del_files[0] = "abc.html", $del_filse[1] = "poo.txt" etc.

Anyway to do this with small?
.Prometheus. is offline
Send a message via AIM to .Prometheus. Send a message via MSN to .Prometheus.
.Prometheus.
Member
Join Date: Sep 2004
Old 10-30-2004 , 09:38  
Reply With Quote #2

I could do this the hard way...

Code:
new thing[32] = "1|2|3|4|5|6|7|8"; new Float:explode_int = 1; new item_m[8][64] new item_m_array_int = -1; while(explode_int) {     ++item_m_array_int     copyc(thing,31,item_m[item_m_array_int],"|");     replace(thing,31,"%s|",item_m[item_m_array_int]);     if(item_m_array_int => 8) {         explode_int = 0;     } }
.Prometheus. is offline
Send a message via AIM to .Prometheus. Send a message via MSN to .Prometheus.
.Prometheus.
Member
Join Date: Sep 2004
Old 10-30-2004 , 10:07  
Reply With Quote #3

Ok I can't get copyc to work...I put ch as "|" and it said arg mismatch...

I changed it to a number and it was fine? Erm...Help?
.Prometheus. is offline
Send a message via AIM to .Prometheus. Send a message via MSN to .Prometheus.
AssKicR
Veteran Member
Join Date: Mar 2004
Location: Norway-Europe(GTM+1)
Old 10-30-2004 , 12:22  
Reply With Quote #4

SOmething like this here :-/

Code:
stock explode( output[][], input[], delimiter ) {         new nIdx = 0     new nLen = (1 + copyc( output[nIdx], MAX_STR_LEN-1, input, delimiter ))         while( nLen < strlen(input) )         nLen += (1 + copyc( output[++nIdx], MAX_STR_LEN-1, input[nLen], delimiter )) }
__________________
My Plugins

Got ??
AssKicR is offline
Janzert
Senior Member
Join Date: Mar 2004
Old 10-30-2004 , 14:41  
Reply With Quote #5

Prometheus,

You need to use '|' for the delimiter not "|" (notice the single quotes instead of double quotes). A double quote will create a null terminated string instead of just the delimiter character you're trying to get.

Janzert
Janzert is offline
.Prometheus.
Member
Join Date: Sep 2004
Old 10-31-2004 , 13:42  
Reply With Quote #6

/me worships the almight RPUS AssKicR

Aaaah coolio Janzert, thanks both of you.

Hmm wait....could I put the explode function as native in the inc files?
.Prometheus. is offline
Send a message via AIM to .Prometheus. Send a message via MSN to .Prometheus.
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 16:46.


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