From: Glen Holcomb Date: 2008-08-25T22:51:32+09:00 Subject: Re: split not returning an array? ------=_Part_86025_28188130.1219672547479 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, Aug 25, 2008 at 7:45 AM, Amanda .. wrote: > Hi there, I start out with a string containing at least 1 '+' separating > words in it. I'm trying to get an array using str.split('+'), so I can > use each word to do something different. > > So for example, I have string = "science+students" > Now I want an array: ["science", "students"] > > Problem is, when I do string.split('+'), I'm getting a single string > with the '+' removed, so if I do: > > @cmds = @string.split('+') > > for @item in @cmds > puts 1 > end > > '1' is only outputted once, and if I just print out @cmds, I get > "science students" (I used this to see how many items were in the > 'array') > > Can anyone explain to me what's happening here? It looks like the split > method is returning the original strings without the '+' characters, and > not an array as it should be... > > Thanks for any help! > -- > Posted via http://www.ruby-forum.com/. > > split behaves exactly as documented for me. What is the full section of code where this is happening? Does: string = "science+students" string.split('+') return ["science", "students"] in irb on your machine? -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_86025_28188130.1219672547479--