473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Max allowed length for a javascript string?

Can't find it quickly in the reference books.

Jul 20 '05 #1
5 128892
> 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****@laserlink.net> wrote in message
news:9a**************************@msgid.meganewsse rvers.com...
<snip>
... . The maximum length with will be implementation-specific. ...


In microsoft.public.scripting.jscript, 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****@laserlink.net> wrote in message
news:9a**************************@msgid.meganewsse rvers.com...
<snip>
... . The maximum length with will be implementation-specific. ...


In microsoft.public.scripting.jscript, 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_*********@sprynet.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/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Why not just test it?

String.prototype.repeat = function(n) {
return new Array(n + 1).join(this);
}
var s = "x".repeat(Math.pow(2, 23)) + "y";
document.write(s.charAt(s.length - 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.pow(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****@laserlink.net> wrote in message
news:9a**************************@msgid.meganewsse rvers.com...
<snip>
... . The maximum length with will be implementation-specific. ...


In microsoft.public.scripting.jscript, 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*****@agricoreunited.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
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),...
7
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;...
0
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...
8
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...
5
by: Daniel | last post by:
c# string size limit? length of string limit?
5
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...
7
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...
4
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...
7
by: deepthi230 | last post by:
how can i convert a javascript string to xml string?
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.