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

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -