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

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -