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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -