WJ wrote:
> Oforth:
>
> : parse |result|
> wordsWith(':') dup
> extract(1,1) asListBuffer -> result
> last wordsWith(';') map(#[strip])
> result addAll
> result put(2, result at(2) words last)
> result removeLast words first result add
> result ;
>
> "animal: we have cats; dogs; monkey and other animals"
> "food: different types like rice; beans; potato and some other"
> "car: we have mercedes; ford; opel; mazda plus other cars"
> [,,]
> apply(#[parse println])
>
>
> [animal, cats, dogs, monkey]
> [food, rice, beans, potato]
> [car, mercedes, ford, opel, mazda]
Ruby:
"
animal: we have cats, dogs, monkey and other animals
food: differet types like rice, beans, potato and some other
car: we have mercedes, ford, opel, mazda plus other cars
".strip.each_line{|line|
category, text = line.split(":")
types = text.split(/, */).
map.with_index{|str,i| str.split[i.zero? ? -1 : 0]}
p [category, *types]
}
===>
["animal", "cats", "dogs", "monkey"]
["food", "rice", "beans", "potato"]
["car", "mercedes", "ford", "opel", "mazda"]
--
In the United States in 2005, 37,460 white females were sexually assaulted or
raped by a black man, while between zero and ten black females were sexually
assaulted or raped by a white man. What this means is that every day in the
United States, over one hundred white women are raped or sexually assaulted by
a black man. --
http://archive.frontpagemag.com/readArticle.aspx?ARTID=26368