$variable = explode("ter_to_search_for",$variable)
then the variable becomes an array with all the split parts in it.
how can i do this in purebasic?
big thx and stay tuned!
j0sh


 j0sh
 j0sh 
Code: Select all
array explode ( string separator, string string [, int limit])
Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string separator. If limit is set, the returned array will contain a maximum of limit elements with the last element containing the rest of string.
Code: Select all
;
; Remember to turn on inline ASM!
;
Procedure.l CountChars(a.s,s.s)
  !MOV edi,dword[esp]    ;pointer to the first character in string (first function parameter)
  ;firstly we must found the lenght of the string:
  !CLD              ;clear DF (Direction Flag). Could be not necessary.
  !XOR al,al       ;set NULL character in AL register
  !XOR ebx,ebx  ;init counter
  !MOV ecx,ebx    ;lets set 4294967295 ($FFFFFFFF) characters maximum
  !DEC ecx
  !REPNZ scasb    ;repeat comparing AL CPU register content with [edi]
  !JECXZ go    ;if NULL byte is not found within those 4294967295 characters then exit giving 0
  !NOT ecx     ;else, some adjusts. Now we have the lenght at ecx register
  !MOV edi,dword[esp]     ;point again to the first character in string (first function parameter)
  !MOV eax,dword[esp+4]
  !MOV al,byte[eax]    ;al=character to find
  !@@:REPNZ scasb   ;repeat comparing AL CPU register content with [edi]
  !JECXZ go     ;until ecx value is reached
  !INC ebx       ;or a match is found
  !JMP @r       ;continue comparing next character
  !go:MOV eax,ebx   ;output the matches counter
  ProcedureReturn
EndProcedure 
my_string.s = "this is the string I want to split"
num_occurances.l = CountChars(my_string," ")
Dim a_explode.s(num_occurances)
For counter = 0 To num_occurances
  
   ;
   ; StringField indexes start at 1, not zero.. That's the reason for the +1
   ;
    new_string.s = StringField(my_string, counter + 1, " ")
    
    a_explode(counter) = new_string
    
Next
For counter = 0 To num_occurances
 
  Debug a_explode(counter)
   
Next