On May 7, 4:12 pm, akbarhome <akbarh... / gmail.com> wrote: > On May 7, 2:39 pm, Nanyang Zhan <s... / hotmail.com> wrote: > > > > > Don't get me wrong, because I just want to know how to separate English > > words from a string with ruby. > > There are strings (UTF-8 encoded) to record people's name, > > like: > > > ëñ¥¥ì¢¥±¥Ä¥ê¾Îëìëû¥· Morgan Freeman > > ÉÛ»Û°ÒÍø»Û Bruce Willis > > Íû¾®ÌÀ Lee xiao ming > > these strings containing Chinese name(without space between characters), > > separated by a space, following an English name > > > or > > Frank Darabont > > Just an English name. > > > Would you give me an idea how to separate these Chinese characters(if > > any)? > > > -- > > Posted viahttp://www.ruby-forum.com/. > > a = File.open('a.txt') > a.each {|x| puts x.split(' ', 2) } > Output: > ëñ¥¥ì¢¥±¥Ä¥ê¾Îëìëû¥· > Morgan Freeman > ÉÛ»Û°ÒÍø»Û > 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.