Robert Klemme
4/6/2009 2:37:00 PM
On 06.04.2009 16:21, Tomas Na wrote:
> I am trying to split a string by spaces and then loop through each
> entry, adding it to an array if it is more then 4 characters long and
> not already in the array.
Well, you could do that in one go:
tags = Set.new
....
s_text.scan(/\S{5,}/) {|match| tags << match}
> I haven't got very far with it, but I have come up against this problem
> where split just crashes my program with no errors.
>
> def GetUniqueTextValues(sText)
Convention in Ruby is to use lower case names for methods and also
separate words by underscores. This avoids confusing methods with classes.
def get_unique_text_values
> aTags = Array.new
That Array creation is superfluous.
> puts sText
> aTags = sText.split
> puts sText
>
> return aTags
> end
>
> What happens when I run this is the text is output for the first puts,
> but not for the second.
This is not exactly what you called a "crash" unless the process would
terminate. Does it? If not, how long did you wait for the split to
complete? What version of Ruby are you using and what is your input
String - especially how long is it?
> If I comment out the split then the text is
> output twice, once for each puts. I read in the ruby docs that split
> with no parameters will split by space, but I also tried split(' ') and
> split(/ /) with the same crashing effect.> I use split another place in
> my program like this:
>
> saHeadParts = line.split(/: /)
>
> and it works fine, so I don't understand why it wont work this time. Can
> anyone help me fix this?
Please provide more information.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end