|
RE: [jruby-user] Iterating over characters in a String ?: msg#00143lang.jruby.user
Have you taken a look at Rails' ActiveSupport::Multibyte? It builds some unicode aware methods on top of the standard string class. It looks to be the most complete unicode implementation for Ruby now, and there has been talk to provide a native JRuby implementation of Multibyte to speed up performance in a JVM. http://www.fngtps.com/2006/10/activesupport-multibyte Peter -----Original Message----- From: Leonel Gayard [mailto:leonel.gayard@xxxxxxxxx] Sent: Friday, November 16, 2007 9:46 AM To: user@xxxxxxxxxxxxxxxxxx Subject: [jruby-user] Iterating over characters in a String ? I'm looking for some way to iterate over the characters of a String in Ruby. Ruby's class String does not provide a method each_char, nor does JRuby's class String. Instead, both provide method each_byte. Now, Ruby does not do Unicode. What a shame for a language developed in Japan ! Instead, it believes that the size of a char is 8 bits. Thus, Ruby thinks that Matz' name, which is 松本行弘, has 12 characters: matz = '松本行弘' matz.length -> 12 Help. How do I translate the following Java method into JRuby ? void m(String s) { for (int i = 0; i < s.length(); i++) { System.out.println(s.charAt(i)); } } The following does *not* work in Ruby, because it outputs each byte, instead of each letter. def each_char(str) 0...str.length do |i| puts str[i] end end --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [jruby-user] Iterating over characters in a String ?: 00143, Leonel Gayard |
|---|---|
| Next by Date: | Re: [jruby-user] Iterating over characters in a String ?: 00143, Leonel Gayard |
| Previous by Thread: | [jruby-user] Iterating over characters in a String ?i: 00143, Leonel Gayard |
| Next by Thread: | Re: [jruby-user] Iterating over characters in a String ?: 00143, Leonel Gayard |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |