split() function
- Posted by No Solution <solutionnone at HOTMAIL.COM> Apr 30, 2000
- 433 views
Hello all . Anybody that's programmed in perl or PHP knows that the split() function is extremely useful. When i first downloaded Euphoria, I was suprised that there was no split function seeing as it's main datatype can be used to express strings. So one day i set out to write my own split() function, after several bad attempts, i came to a very obvious and efficient function. here it is : global function split(atom char, sequence string) sequence ret integer c ret = {{}} c = 1 for i = 1 to length(string) do if string[i] = char then ret = append(ret,{}) c = length(ret) else ret[c] &= string[i] end if end for return ret end function so far you can only use atoms to use a delimiters to split strings by. use the function like this: sequence s,words s = "hello!world" words = split('!',s) anybody who writes euphoria programs that require text parsing would find this function extremely useful,if they haven't written it already. Ian Smith ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com