Pooh program example 03-string-split.p
# test split library function - string split into array. text = 'the quick brown fox jumped over the lazy dog' println( ~msg '*** split in for loop ***' ) for f split( ~string text ) println( ~msg f ) end text = 'the quick brown fox jumped over the lazy dog' tokens = split( ~string text ) println( ~msg '*** split returning an array of tokens ***' ) for f tokens println( ~msg f ) end text = 'the:quick:brown:fox:jumped:over:the:lazy:dog twice' println( ~msg '*** split with the : separator ***' ) for f split( ~string text ~separator ':' ) println( ~msg f ) end
*** split in for loop *** the quick brown fox jumped over the lazy dog *** split returning an array of tokens *** the quick brown fox jumped over the lazy dog *** split with the : separator *** the quick brown fox jumped over the lazy dog twiceTrace output for 03-string-split.p
003|text = 'the quick brown fox jumped over the lazy dog' 005|println( ~msg '*** split in for loop ***' )... 006|for ... split( ~string text:'the quick brown fox jumped over the lazy dog' )... 006| for f = 'the' 007| println( ~msg f:'the' )... 006| end 006| for ... 006| for f = 'quick' 007| println( ~msg f:'quick' )... 006| end 006| for ... 006| for f = 'brown' 007| println( ~msg f:'brown' )... 006| end 006| for ... 006| for f = 'fox' 007| println( ~msg f:'fox' )... 006| end 006| for ... 006| for f = 'jumped' 007| println( ~msg f:'jumped' )... 006| end 006| for ... 006| for f = 'over' 007| println( ~msg f:'over' )... 006| end 006| for ... 006| for f = 'the' 007| println( ~msg f:'the' )... 006| end 006| for ... 006| for f = 'lazy' 007| println( ~msg f:'lazy' )... 006| end 006| for ... 006| for f = 'dog' 007| println( ~msg f:'dog' )... 006| end 006| for ... 006| end # finish for loop 010| text = 'the quick brown fox jumped over the lazy dog' 011| ... = split( ~string text:'the quick brown fox jumped over the lazy dog' )... 011| tokens = split( ~string text:'the quick brown fox jumped over the lazy dog' ):-> [ 'the', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog' ] 013| println( ~msg '*** split returning an array of tokens ***' )... 015| for f = 'the' 016| println( ~msg f:'the' )... 015| end 015| for ... 015| for f = 'quick' 016| println( ~msg f:'quick' )... 015| end 015| for ... 015| for f = 'brown' 016| println( ~msg f:'brown' )... 015| end 015| for ... 015| for f = 'fox' 016| println( ~msg f:'fox' )... 015| end 015| for ... 015| for f = 'jumped' 016| println( ~msg f:'jumped' )... 015| end 015| for ... 015| for f = 'over' 016| println( ~msg f:'over' )... 015| end 015| for ... 015| for f = 'the' 016| println( ~msg f:'the' )... 015| end 015| for ... 015| for f = 'lazy' 016| println( ~msg f:'lazy' )... 015| end 015| for ... 015| for f = 'dog' 016| println( ~msg f:'dog' )... 015| end 015| for ... 015| end # finish for loop 019| text = 'the:quick:brown:fox:jumped:over:the:lazy:dog twice' 021| println( ~msg '*** split with the : separator ***' )... 022| for ... split( ~string text:'the:quick:brown:fox:jumped:over:the:lazy:dog twice' ~separator ':' )... 022| for f = 'the' 023| println( ~msg f:'the' )... 022| end 022| for ... 022| for f = 'quick' 023| println( ~msg f:'quick' )... 022| end 022| for ... 022| for f = 'brown' 023| println( ~msg f:'brown' )... 022| end 022| for ... 022| for f = 'fox' 023| println( ~msg f:'fox' )... 022| end 022| for ... 022| for f = 'jumped' 023| println( ~msg f:'jumped' )... 022| end 022| for ... 022| for f = 'over' 023| println( ~msg f:'over' )... 022| end 022| for ... 022| for f = 'the' 023| println( ~msg f:'the' )... 022| end 022| for ... 022| for f = 'lazy' 023| println( ~msg f:'lazy' )... 022| end 022| for ... 022| for f = 'dog twice' 023| println( ~msg f:'dog twice' )... 022| end 022| for ... 022| end # finish for loop