From: Craig W. <cwi...@ma...> - 2009-01-18 23:06:13
|
> On Jan 18, 2009, at 3:22 PM, Harry Maclean wrote: > Sorry if this is an obvious or stupid question, but I have been > trying for some time to find a way of splitting a string into an > array so that each character is a member of the array. > > I initially tried using ruby's somearray = somestring.split(//), but > I got an error saying: > > NoMethodError: undefined method `empty?' for //:Regexp > /Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/ > oc_attachments.rb:839:in `split' > > I then tried a Cocoa approach with the > componentsSeparatedByCharactersInSet but it gave me an error also. > > Am I missing an obvious method of splitting a string into an array? Are you sure that somestring is actually a string? Your code works fine OMM. You can also use this. >> 'this is a string'.scan(/./) => ["t", "h", "i", "s", " ", "i", "s", " ", "a", " ", "s", "t", "r", "i", "n", "g"] |