473,802 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Max allowed length for a javascript string?

Can't find it quickly in the reference books.

Jul 20 '05 #1
5 129252
> Can't find it quickly in the reference books.

The ECMAScript Programming Language Specification does not specify a maximum
length. The maximum length with will be implementation-specific. For some
implementations , it will be a function of available memory, but you should not
rely on that if portability is important.

http://www.ecmascript.org

Jul 20 '05 #2
"Douglas Crockford" <no****@laserli nk.net> wrote in message
news:9a******** *************** ***@msgid.megan ewsservers.com. ..
<snip>
... . The maximum length with will be implementation-specific. ...


In microsoft.publi c.scripting.jsc ript, Michael Harris
(Microsoft.MVP. Scripting), who might be expected to know, quoted:-

<quote Message-ID: <#C************ **@TK2MSFTNGP12 .phx.gbl>
In JScript, variant string variables have the same limit as in VBScript,
up to 2^31 characters.

String *literals* (as in "this is a literal") have (IIRC) a limit ~2^10
(1024) characters.
</quote>

- for the JScript implementation.

Richard.
Jul 20 '05 #3


Richard Cornford wrote:

I can tell from experience it's not 1024. The last string I used was over
23K bytes. However, I just wanted to make sure the limit wasn't something
like 2^16, which I'll collide with shortly. It's just a packing script
to export to MS Access from webdom. Since javascript has C as it's
progenitor, that's probably the limit. I've forgotten that limit, and
there's no book handy.

Wade
"Douglas Crockford" <no****@laserli nk.net> wrote in message
news:9a******** *************** ***@msgid.megan ewsservers.com. ..
<snip>
... . The maximum length with will be implementation-specific. ...


In microsoft.publi c.scripting.jsc ript, Michael Harris
(Microsoft.MVP. Scripting), who might be expected to know, quoted:-

<quote Message-ID: <#C************ **@TK2MSFTNGP12 .phx.gbl>
In JScript, variant string variables have the same limit as in VBScript,
up to 2^31 characters.

String *literals* (as in "this is a literal") have (IIRC) a limit ~2^10
(1024) characters.
</quote>

- for the JScript implementation.

Richard.


Jul 20 '05 #4
"Wade G. Pemberton" <w_*********@sp rynet.com> writes:
I can tell from experience it's not 1024. The last string I used was over
23K bytes.
It is highly browser dependent.

I just created a string literal in IE 6 that was 2^20 (~1M) characters
long. It took a while to parse! I also created a string that was 2^24
characters long. Then I wrote it as a string literal, and it hasn't
finished parsing it yet.

Mozilla breaks between 2^15 and 2^16 (32768 and 65536).

Opera 7.21 breaks somewhere between 2^11 and 2^12 (2048 and 8192).
[2^16?] Since javascript has C as it's progenitor, that's probably the
limit.


C is not Javascript's progenitor any more than Java is. All they share
is the syntax.

C has no inherent limits, although most implementations have a size_t
that is 32-bit.

/L 'please trim your quotes'
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Why not just test it?

String.prototyp e.repeat = function(n) {
return new Array(n + 1).join(this);
}
var s = "x".repeat(Math .pow(2, 23)) + "y";
document.write( s.charAt(s.leng th - 1));

Anything larger in IE and I get an Out of memory error trying to *construct* the
string, but that's probably due to the implementation I'm using (constructing
the array and using .join()). I was able to get Firebird up to
..repeat(Math.p ow(2, 22)) before it completely gave up the ghost and stopped
responding. Interestingly enough, Opera 7.21 seemed particularly adept at this
task, and was able to construct a string 2^31 long almost instantly.

As for any limit in C having an effect on a limit in JavaScript, that's silly. A
String in JavaScript is an object containing a set of unicode characters, as
well as various properties and methods, isn't a string in C simply an area of
memory at begun at some location, and terminated by a \0? So why should there be
an artificial limit in C at all?

Considering the modern browsers I tested were capable of setting and retrieving
the last character of a string at least 2^20 long, I doubt you'll have any
problems for the foreseeable future.

"Wade G. Pemberton" wrote:
Richard Cornford wrote:

I can tell from experience it's not 1024. The last string I used was over
23K bytes. However, I just wanted to make sure the limit wasn't something
like 2^16, which I'll collide with shortly. It's just a packing script
to export to MS Access from webdom. Since javascript has C as it's
progenitor, that's probably the limit. I've forgotten that limit, and
there's no book handy.

Wade
"Douglas Crockford" <no****@laserli nk.net> wrote in message
news:9a******** *************** ***@msgid.megan ewsservers.com. ..
<snip>
... . The maximum length with will be implementation-specific. ...


In microsoft.publi c.scripting.jsc ript, Michael Harris
(Microsoft.MVP. Scripting), who might be expected to know, quoted:-

<quote Message-ID: <#C************ **@TK2MSFTNGP12 .phx.gbl>
In JScript, variant string variables have the same limit as in VBScript,
up to 2^31 characters.

String *literals* (as in "this is a literal") have (IIRC) a limit ~2^10
(1024) characters.
</quote>

- for the JScript implementation.

Richard.


--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2673
by: Peter | last post by:
Hi, I try to make up a javascript string which contains numeric numbers in any positions. For example, I want to make a string: secretcode, where secretcode.charAt(0)==(-21), secretcode.charAt(5)==(-14). Is there any way to accomplish this task? Thanks in advance, Peter
7
2554
by: Matt | last post by:
Have below code AcctNbr give me result of 30. That is the database column length, Column stores 10 why is giving me 30 ? while(objRead.Read()) { AcctNbr = (string)objRead.ToString().Length; Console.WriteLine("Length is {0}",AcctNbr.Length); }
0
1093
by: gauthier | last post by:
Excuse me for a so simple question, but is there any method in the framework that encode strings as javascript string ie: "it's 9 o'clock" should be encoded as "it\'s 9 o\'clock" What I need is something like javascriptEncode( ) method described at http://nindssearch.ninds.nih.gov/verity_web/templates/jsp/doc/examples/util/StringHelper.html
8
2307
by: Pavils Jurjans | last post by:
Hello, I have been developing an Ajax-style framework for couple of years now. Now I am reworking some parts of it. The problem was that I used to use JSON for JavaScript value serialization/deserialization, but this approach has some limitations when it comes to large data - the JavaScript at the client side has too much load working with it. So, I thought, I'd rework the serialization to XML format. The idea is short-as-possible...
5
5443
by: Daniel | last post by:
c# string size limit? length of string limit?
5
2768
by: Olly | last post by:
Hello Group: I'd be grateful to anyone who can help me with Javascript form. :-) I want users to submit a web form, but to stop the form submission if any of my text fields contain specific value (e.g. "http"). I incorporated "http" detection bits of script into my existing function (only for one of my fields for now ), but for some reason this script doesn' work, probably, because of the wrong syntax. =============
7
16574
by: andrewfsears | last post by:
I have a question: I was wondering if it is possible to simulate the multiple constructors, like in Java (yes, I know that the languages are completely different)? Let's say that I have a class called "Point" which would have two values "x" and "y". Now, let's say if it were the Java version, I would want two constructors: one that accept two numbers, the other accepts a string:
4
46140
by: krndhi1983 | last post by:
Hi to All, I need a query to Find out the max.length of string in a particular Column. For ex. In a table,One of the column name is EmpName, In this column I want to select max lenth of the String. Any one can help Me?
7
4235
by: deepthi230 | last post by:
how can i convert a javascript string to xml string?
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10538
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.