Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a service writing remote files, but it requires a byte array as input. Rest of the interface provides only JavaScript unicode strings. No way to write them then.

I found something like this in MDC:

var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
                .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
var s = {};
var tt = 'test string';
var data = converter.convertToByteArray(tt, s);

According to what they say in MDC, this should do exactly what I need, but it fails with this:

Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIScriptableUnicodeConverter.convertToByteArray]

In docs there is the string must not be UTF-16, and I've read JS uses UTF-16 by default.

Any other ways to produce this damn byte array from string?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You must assing the charset! For example: converter.charset = 'UTF-8';

share|improve this answer
    
Thanks. It works. –  Harry Dec 22 '10 at 13:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.