Google

def check_encoding(str) if str=~/^\376\377/ UTF16 #unicode big endian elsif str=~/^\377\376/ UNILE #unicode litle endian else UTF8 end end