By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

Maximum Line and String Lengths

P: n/a
Is there a maximum length for Javascript program lines?

What about strings? Is there a limit on string length?

I found some references that said the maximum string length was 256
characters, but I have a program that created a string of over 25,000
characters (the browser was Konqueror).

Are there limits on these lengths? If I require a newer browser for the
program I'm writing, would that change the situation?

Thanks!

Hal
Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hal Vaughan hu kiteb:
Is there a maximum length for Javascript program lines?
The maximum limit on line length is whatever you feel comfortable
reading and editing. Personally, any code of mine that won't fit on the
screen without wrapping will be rewritten.

There probably is some limit somewhere, but there isn't any good reason
to push against it that I can see.
What about strings? Is there a limit on string length?

I found some references that said the maximum string length was 256
characters, but I have a program that created a string of over 25,000
characters (the browser was Konqueror).

Are there limits on these lengths? If I require a newer browser for
the program I'm writing, would that change the situation?


I have yet to come across a situation where the maximum string length
became an issue before teh speed at which it could be processed became
an issue. One of the array nests in a scipt of mine is 20k in length. I
consider that neer the upper limit of acceptable processing speed given
teh amount of images it wangs in the process of reading the array.
--
--
Fabian
This post is not associated in any way with forum4designers dot com.
Permission is specifically denied for that website to archive this post
or display it in any way.

Jul 20 '05 #2

P: n/a
Thanks!

Fabian wrote:
Hal Vaughan hu kiteb:
Is there a maximum length for Javascript program lines?


The maximum limit on line length is whatever you feel comfortable
reading and editing. Personally, any code of mine that won't fit on the
screen without wrapping will be rewritten.

There probably is some limit somewhere, but there isn't any good reason
to push against it that I can see.


For general HTML and JavaScript I don't like pushing it, either. I read one
page (while I was searching for a maximum line length) that said in pre
Netscape 3.0 days he saw many pages written in 1 line to save on transfer
speeds with slower dialups. While interesting, that doesn't seep to apply
any longer.
What about strings? Is there a limit on string length?

I found some references that said the maximum string length was 256
characters, but I have a program that created a string of over 25,000
characters (the browser was Konqueror).

Are there limits on these lengths? If I require a newer browser for
the program I'm writing, would that change the situation?


I have yet to come across a situation where the maximum string length
became an issue before teh speed at which it could be processed became
an issue. One of the array nests in a scipt of mine is 20k in length. I
consider that neer the upper limit of acceptable processing speed given
teh amount of images it wangs in the process of reading the array.


I'm doing something similar. I am working with up to 3 dimensional arrrays.
In a few cases, I have to store long lists of true/false settings. I'm
storing the arrays by using loops to convert them to a string and storing
that in a hidden field in the form. This also makes it easy for me to move
the data back and forth from Perl to JavaScript programs. However, that
results in the long string I mentioned. The odd thing is that it loads in
quickly and is quickly converted from a one line string to an array, but it
seems to take longer to store the array in one long string.

Thanks for the help!

Hal
Jul 20 '05 #3

P: n/a
"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:eOMOb.86011$nt4.130649@attbi_s51...
<snip>
... . The odd thing is that it loads in quickly and is
quickly converted from a one line string to an array, but it
seems to take longer to store the array in one long string.


Look at the Array.prototype.join method. E.g.:-

var ar = [true,false,true,false,true];

alert('var ar = ['+ ar.join(',') +'];');

As it is a native code method it is faster than looping through an
array.

It doesn't necessarily help with nested arrays but there are ways of
working round that by assigning custom toString function that call -
this.join() - on the array to which they are attached. E.g.:-

var ar2D = [true,
false,
["string1","string2"],
true,
false,
true
];

ar2D[2].toString = function(){
return '[\"'+this.join('\",\"')+'\"]';
};

alert('var ar2D = ['+ar2D.join(',')+'];');

Richard.
Jul 20 '05 #4

P: n/a
Richard Cornford wrote:
"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:eOMOb.86011$nt4.130649@attbi_s51...
<snip>
... . The odd thing is that it loads in quickly and is
quickly converted from a one line string to an array, but it
seems to take longer to store the array in one long string.


Look at the Array.prototype.join method. E.g.:-

var ar = [true,false,true,false,true];

alert('var ar = ['+ ar.join(',') +'];');

As it is a native code method it is faster than looping through an
array.

It doesn't necessarily help with nested arrays but there are ways of
working round that by assigning custom toString function that call -
this.join() - on the array to which they are attached. E.g.:-

var ar2D = [true,
false,
["string1","string2"],
true,
false,
true
];

ar2D[2].toString = function(){
return '[\"'+this.join('\",\"')+'\"]';
};

alert('var ar2D = ['+ar2D.join(',')+'];');

Richard.


I didn't know about these methods (I'm self taught, so I miss a lot in every
language -- it's frustrating). I'll look into them. They may help, but in
most cases I'm working with nested arrays. While your example of creating
a 2d array would work, I'm not sure how to be sure, when converting an
array to a string, that a particular element is an array instead of a
string. It seems I'd still have to do a lot of looping.

I'll have to investigate this, since it could save me a lot of time. The
current code seems to work fast enough, but it would make development on
the rest of the program faster and easier (and more efficient code) if I
could get the process you've shown to work on a multi-dimensional array.

Thanks!

Hal
Jul 20 '05 #5

P: n/a
Hal Vaughan wrote:
Richard Cornford wrote:

"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:eOMOb.86011$nt4.130649@attbi_s51...

<--snip-->

I didn't know about these methods (I'm self taught, so I miss a lot in every
language -- it's frustrating). I'll look into them. They may help, but in
most cases I'm working with nested arrays. While your example of creating
a 2d array would work, I'm not sure how to be sure, when converting an
array to a string, that a particular element is an array instead of a
string. It seems I'd still have to do a lot of looping.


To find out if its an array or a string, use the typeof operator

alert(typeof(myVar))

<URL:
http://msdn.microsoft.com/library/de...soprtypeof.asp
/>


--
Randy

Jul 20 '05 #6

P: n/a
"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:eNUOb.100123$8H.145430@attbi_s03...
<snip>
I'll have to investigate this, since it could save me a lot
of time. The current code seems to work fast enough, but it
would make development on the rest of the program faster and
easier (and more efficient code) if I could get the process
you've shown to work on a multi-dimensional array.


When - join - is called it type-converts each element in the Array to a
string so when one of those elements is an Array the type-converting is
done by calling its toString method. If that Array contains another then
it too will be type-converted by having its toString method called, so
the effect is recursive to any depth of nesting. That is fairly
reliable.

How practical it would be to use a combination of Array.prototype.join
and custom toString functions to serialise nested arrays into strings is
going to depend quite a lot on the nature of those arrays. For example,
If none of the arrays ever contained string values the whole process
could be relatively simple (assuming there was no need to call the
toString method of an Array elsewhere) as:-

Array.prototype.toString = function(){
return '['+this.join(',')+']';
}

-would result in that custom toString method being inherited by all of
the Arrays used. Indeed strings are only a problem if you want to have
them delimited with quote marks (or similar), if that isn't important
then the above should work anyway.

Richard.
Jul 20 '05 #7

P: n/a
Randy Webb wrote:
Hal Vaughan wrote:
Richard Cornford wrote:

"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:eOMOb.86011$nt4.130649@attbi_s51...

<--snip-->

I didn't know about these methods (I'm self taught, so I miss a lot in
every
language -- it's frustrating). I'll look into them. They may help, but
in
most cases I'm working with nested arrays. While your example of
creating a 2d array would work, I'm not sure how to be sure, when
converting an array to a string, that a particular element is an array
instead of a
string. It seems I'd still have to do a lot of looping.


To find out if its an array or a string, use the typeof operator

alert(typeof(myVar))

<URL:

http://msdn.microsoft.com/library/de...soprtypeof.asp />


Thanks.

Again, didn't know, or even have a clue of this function. Sometimes I don't
even find things like this in a reference book because I'm not sure what
I'm looking for. This will be a help to me in the future.

Hal
Jul 20 '05 #8

P: n/a
Richard Cornford wrote:
"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:eNUOb.100123$8H.145430@attbi_s03...
<snip>
I'll have to investigate this, since it could save me a lot
of time. The current code seems to work fast enough, but it
would make development on the rest of the program faster and
easier (and more efficient code) if I could get the process
you've shown to work on a multi-dimensional array.


When - join - is called it type-converts each element in the Array to a
string so when one of those elements is an Array the type-converting is
done by calling its toString method. If that Array contains another then
it too will be type-converted by having its toString method called, so
the effect is recursive to any depth of nesting. That is fairly
reliable.

How practical it would be to use a combination of Array.prototype.join
and custom toString functions to serialise nested arrays into strings is
going to depend quite a lot on the nature of those arrays. For example,
If none of the arrays ever contained string values the whole process
could be relatively simple (assuming there was no need to call the
toString method of an Array elsewhere) as:-

Array.prototype.toString = function(){
return '['+this.join(',')+']';
}

-would result in that custom toString method being inherited by all of
the Arrays used. Indeed strings are only a problem if you want to have
them delimited with quote marks (or similar), if that isn't important
then the above should work anyway.

Richard.


This is definitely something I'll play around with so I can see it work and
incorporate it into my code.

Thanks, again!

Hal
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.