module FlydataCore class StringUtils def self.replace_invalid_utf8_char(str, replacement = '?') str.encode("UTF-16BE", invalid: :replace, undef: :replace, replace: replacement).encode("UTF-8") end end end