View Full Version : JavaScript maximum string length?
wkkor
04-10-2007, 04:26 AM
Anyone know what the maximum of string limit allow to assign to a variable in Javascript?
Jon Hanlon
04-10-2007, 05:27 PM
There is no reference to the maximum length in the ECMA262 specification. It is usually limited by your machine's memory.
BTW, to quickly hang a browser:
var str = "x"; while (true) str += str;
wkkor
04-10-2007, 10:34 PM
I had encounter a problem which I had use AJAX to read a XML file, there have a tag name "content" which contain quite long of string. While I output the value for the tag, it was return incomplete of the value. It was working fine with the rest of the tag which contain shorter value. Additional, I can get the complete XML content when I use browser to open it. So I just wondering what cause this issue.
Jon Hanlon
04-10-2007, 10:48 PM
XML files are huge by their nature. I have loaded several Meg of XML without a hiccup.
Make sure "content" does not contain any < (<) or & (&) characters unless you have wrapped it in a CDATA section.
You can also use Ajax to inspect the headers of the request; this can often shed some light.
Jon Hanlon
04-11-2007, 12:44 AM
Found this:
JScript 8.0
String Data Type (JScript)
The length of a String can be from zero to approximately two billion characters. Each character is a 16-bit Unicode value.
http://msdn2.microsoft.com/en-us/library/8xzsk62k.aspx
wkkor
04-11-2007, 01:55 AM
oh... really thanks a lot. I had use the CDATA in this case, but there have another concern now. While I retrieve the nodeValue, it will return the CDATA..... as well. Is there anyway to escape it? Or how should i retrieve the value?
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.