How to Convert Ruby UTF String -
i have string data, looks this:
"\x00m\x00o\x00d\x00e\x00l\x00"
when run:
puts "\x00m\x00o\x00d\x00e\x00l\x00"
i see like:
'model'
but understand, string still encoded differently. puts seems apply translation.
i'd convert "\x00m\x00o\x00d\x00e\x00l\x00" 'model' use elsewhere, strangely encoded string doesn't work me.
anyone know way this? i've searched eyeballs out.
so solution came to, helped come this:
encoding_options = { invalid: :replace, undef: :replace, replace: '', universal_newline: true } data.gsub("\x00", '') .encode(encoding.find('ascii'), encoding_options)
Comments
Post a Comment