473,396 Members | 1,834 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,396 software developers and data experts.

Maximum Line and String Lengths

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
8 4706
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
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
"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
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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Lobang Trader | last post by:
Hi all, I am trying to create a username and a password class. I would like to know what are the RECOMMENDED minimum and maximum length for both fields? These fields will be something like...
0
by: John G | last post by:
How can I Programmatically access maximum path, file, and sum of both lengths? I am using VB.NET 2003. The PathTooLongException indicates that a path < 248 characters, filename < 260...
6
by: veerleverbr | last post by:
Hi, I have the following html: <div id="content"> <div id="leftpart">...</div> <div id="rightpart">...</div> </div> leftpart en rightpart are in the css set to float left. The content of...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
7
by: Martin Pöpping | last post by:
Hello, does a String in C# have a maximum length? I tried to write a ToString Method of my class containing a hashtable. At the beginning of the method i defined a String "ret". In every...
7
by: Curious | last post by:
Hi, I need advice on how to set the maximum property of my progress bar. I read a huge file so I need a progress bar when I read it. However, I don't know how many records are there in the...
0
by: Fredrik Lundh | last post by:
maurizio wrote: What kind of file is it? Did you pick numpy because you want to do matrix operations (beyond just finding a maximum value), or was it just the first thing you stumbled upon...
1
by: maurizio | last post by:
thank you for your answer actually i've to do some statistics (maximum,minimum,mean,standard deviation,....) of a file of data in which each column is a particular type of data. (the file is a tab...
53
by: Gianni Mariani | last post by:
Do you have a preference on maximum line width for C++ code? I've seen the craziest debates on this most silly of topic. I have witnessed engineers spent oodles of time fiddling with line...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.