From: John Joyce Date: 2007-05-07T21:31:36+09:00 Subject: Re: separate Chinese and English! with Ruby On May 7, 2007, at 8:35 PM, akbarhome wrote: > On May 7, 5:17 pm, Nanyang Zhan wrote: >> Akbar Home wrote: >>> On May 7, 4:12 pm, akbarhome wrote: >>>>> 布鲁斯·威利斯 Bruce Willis >> >>>> 李小明 >>>> Lee xiao ming >> >>> Sorry. Fixed version: >>> a.each {|x| >>> if x[0].to_i > 128 then >>> puts x.split(' ', 2) >>> else >>> puts x >>> end >>> } >> >>> This code is quick and dirty. >> >> Thanks. >> But I was wrong. There are more Characters than Chinese and >> English that >> compose the strings. Now I see characters like Ô, é, á... if x >> is one of >> these, x[0]> 128 as Chinese does, but I only want to separate >> Chinese. >> >> so do you know what exactly range of the value Chinese Characters >> will >> return? or you can tell me where I can find this kind of information. >> >> -- >> Posted viahttp://www.ruby-forum.com/. > > These: > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/197946 > http://www.khngai.com/chinese/charmap/tbluni.php > > should get you done. > > ustr > => +"摩根·弗里曼" > irb(main):027:0> ustr[0] > => U+6469 > irb(main):028:0> format "%X", ustr[0].to_i.to_s > => "6469" > irb(main):029:0> > > You could identify the encoding or just make it unicode, then check if the characters fall into a range in unicode, that will identify them. One shortcut is checking for leading zeros in the unicode character's code.