I would like to do mungedRegistration = [...] registrationString = NSString.stringWithUTF8String(mungedRegistration) but this results in can't convert Array into String (TypeError) What is the best approach here? I do need my munged registration to be an array since I'm initializing it with numbers and then do calculations on these numbers to convert them into character values. Thanks, Joel --- http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
Assuming your array contains ASCII fixnum representation of characters, messaging #pack('c*') on it should give you a string object back. You can look up the documentation of Array#pack for more information. I dislike this method, but here I don't see a better choice. Laurent On Jan 10, 2011, at 1:08 PM, Joel Reymont wrote:
I would like to do
mungedRegistration = [...] registrationString = NSString.stringWithUTF8String(mungedRegistration)
but this results in
can't convert Array into String (TypeError)
What is the best approach here?
I do need my munged registration to be an array since I'm initializing it with numbers and then do calculations on these numbers to convert them into character values.
Thanks, Joel
--- http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On 2011-01-10, at 19:19 , Laurent Sansonetti wrote:
Assuming your array contains ASCII fixnum representation of characters, messaging #pack('c*') on it should give you a string object back.
I dislike this method, but here I don't see a better choice.
numbers = [65, 195, 169] s = numbers.map(&:chr).join you may want to force the string to be treated as UTF-8. s.force_encoding('UTF-8')
On Jan 10, 2011, at 1:22 PM, Caio Chassot wrote:
On 2011-01-10, at 19:19 , Laurent Sansonetti wrote:
Assuming your array contains ASCII fixnum representation of characters, messaging #pack('c*') on it should give you a string object back.
I dislike this method, but here I don't see a better choice.
numbers = [65, 195, 169] s = numbers.map(&:chr).join
you may want to force the string to be treated as UTF-8.
s.force_encoding('UTF-8')
That's much better indeed! Laurent
On Jan 10, 2011, at 9:19 PM, Laurent Sansonetti wrote:
Assuming your array contains ASCII fixnum representation of characters, messaging #pack('c*') on it should give you a string object back.
Do you mean something like [-188,-185,-186].#pack('c*') ?
You can look up the documentation of Array#pack for more information.
How do I lookup documentation? Thanks, Joel --- http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
participants (4)
-
Caio Chassot
-
Henry Maddocks
-
Joel Reymont
-
Laurent Sansonetti