[Project_owners] Re: Converting Strings to Char Arrays in Javascript

WC Leung lwchk2001 at yahoo.com.hk
Tue Aug 2 01:06:25 EDT 2005


Well, I found that I can simply put it into a nsIStringStream:

var ss =
Components.classes["@mozilla.org/io/string-input-stream;1"].getService(Components.interfaces.nsIStringInputStream);
ss.setData(aResult, aResult.length);
var dp = new DOMParser;
var doc = dp.parseFromStream(ss, null, aResult.length, "text/xml");

Since XPCOM is allowed this solution is okay for me.


WC Leung wrote:
> Is there any method faster than the following stupid way? Since I'm
> placing the code on my extension, using XPCOM is okay.
> 
> var count = s.length;
> for (var i = 0; i<count; i++) a[i] = s.charCodeAt(i);
> 
> (N.B. parseFromBuffer of DOMParser needs char array, sigh)


More information about the Project_owners mailing list