473,657 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string length question

Hi;

Whats the maximum string length in Javascript.

Is it the same across all the browsers?

max_s_len = str.length // what the max number of chars we can have is
str?

Regards
Ian

Jul 10 '06 #1
3 7412
ip*****@pipemed ia.co.uk wrote:
Whats the maximum string length in Javascript.
Are you asking about the value of a string primitive or the maximum
length of a string literal in source code? I have never seen stated
values for any maximum length of a string primitive's value (so
probably limited by available memory), and have seen practical tests
going into the hundreds of millions of characters (so probably
exceeding all practical needs). Microsoft used to claim a size limit
for a string literal token, but previous discussions on the subject
proved that the stated figure no longer applied and that the current
real figure is so large that nobody wanted to waste the time necessary
to find out what the limit was.
Is it the same across all the browsers?
There is no reason to expect any limit to be the same across browsers
except by coincidence (such as would result from using a 32bit integer
value to hold the length in different implementations ). If in practice
the limiting factor tends to be available memory then all browsers on
the same machine will have the same available memory.
max_s_len = str.length // what the max number of chars we can
have is str?
If you really must know you can carry out your own tests. You will find
that as the strings get bigger the code slows down so much that you
will get fed up with waiting before you find a definitive answer.

Richard.

Jul 10 '06 #2
ip*****@pipemed ia.co.uk writes:
Whats the maximum string length in Javascript.
The specification does not define a maximal length ...
Is it the same across all the browsers?
.... so it's unlikely that all implementations have the same limits.
max_s_len = str.length // what the max number of chars we can have is
str?
If we insist that all lengths must be expressible exactly as a number,
then the limit will be 2^53. At one byte per character (which is
probably too low), that requires ~8 petabyte of memory. So this
theoretical limit is unlikely to be the limiting factor.

A more likely limit is the range of an UInt32.

A quick script to check the limit (although probably not in reasonable
time):

var N = 32; // vary this and see if it works.
var x = "x";
for(var i = 0; i < N; i++) { x= x+x; };
alert(x.length)

Try this in different browser, starting with a lower N and see when
it breaks :)

In practice, my guess is that long strings take much memory and time
to manipulate, so you'll want to make them shorter long before you
reach a hard limit.
/L
--
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 10 '06 #3
JRS: In article <d5**********@h otpop.com>, dated Mon, 10 Jul 2006
14:38:09 remote, seen in news:comp.lang. javascript, Lasse Reichstein
Nielsen <lr*@hotpop.com posted :
>ip*****@pipeme dia.co.uk writes:
>Whats the maximum string length in Javascript.
>If we insist that all lengths must be expressible exactly as a number,
then the limit will be 2^53. At one byte per character (which is
ECMA requires 16-bit units, but not that they are characters.
>probably too low), that requires ~8 petabyte of memory. So this
theoretical limit is unlikely to be the limiting factor.

A more likely limit is the range of an UInt32.
Some routines use -1 or lower, which could change that to SInt32.

Some implementations seem likely to use DWORD internally, imposing a
limit at 2^32-1 bytes.
>A quick script to check the limit (although probably not in reasonable
time):

var N = 32; // vary this and see if it works.
var x = "x";
for(var i = 0; i < N; i++) { x= x+x; };
alert(x.length )

Try this in different browser, starting with a lower N and see when
it breaks :)
Or put the alert inside the loop, changing it to a Confirm, and continue
the loop until the computer or the user gives out.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 10 '06 #4

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

Similar topics

2
2206
by: Tim Simmons | last post by:
I am stumped. I encoded the action = of my form using GET and I can't seem to get the property/value stuff from it using a JavaScript script I got from the web. I want to create a trivia game where the user gets 1 question at a time and it keeps scoring until the end and gives a summary and I want to do it only in JavaScript (no ASP, PHP, JSP, etc). I tried submitting the quiz page to itself using a query string to keep track of...
51
8258
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct code? many thx!
2
8552
by: Dan Schumm | last post by:
I'm relatively new to regular expressions and was looking for some help on a problem that I need to solve. Basically, given an HTML string, I need to highlight certain words within the text of the string. I had it working somewhat, but ran into problems if one of the highlighted words could also be part of an HTML tag (such as 'Table' or 'Border'). What I need is the regex to find the word, but ignore any words that fall between an HTML...
7
7588
by: Eric | last post by:
Hi All, I need to XOR two same-length Strings against each other. I'm assuming that, in order to do so, I'll need to convert each String to a BitArray. Thus, my question is this: is there an easy way to convert a String to a BitArray (and back again)? I explained the ultimate goal (XORing two Strings) so that, if anyone has a better idea of how to go about this they may (hopefully) bring that up...?
9
9145
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a StringBuilder. At present I am porting a VB6 webclass app to VB.NET and therefore I am trying to make it as efficent as possible via the new functionality of VB.NET.
11
17638
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer s(i)=new string(test) Above line gives - error implicit conversion string to 1-dim array of
7
373
by: junw2000 | last post by:
In the following code: std::string s1; s1 = "ABCDE"; std::cout<<s1<<std::endl; s1 = '\0'; //LINE1 std::cout<<s1<<std::endl; //LINE2 At LINE1, I add a NULL terminator at s1, so s1 should end at s1, right?
17
4709
by: anurag | last post by:
hey can anyone help me in writing a code in c (function) that prints all permutations of a string.please help
7
7810
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}" As far as I know yet -- hence this question -- there is no 'one solution fits all', but instead there are several parts that have to be put together to check. What I have so far is, and would like as much feedback as possible to ensure I've...
0
1160
by: David Hirschfield | last post by:
I'm implementing a relatively simple inter-application communication system that uses asyncore/asynchat to send messages back and forth. The messages are prefixed by a length value and terminator string, to signal that a message is incoming, and an integer value specifying the size of the message, followed by the message data. My question is: how can I produce a short terminator string that won't show up (or has an extremely small...
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
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
8742
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6177
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
4173
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
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.