Solved

max string length?

Posted on 1998-05-27
4
636 Views
Last Modified: 2008-02-01
i'm trying to put a string literal whose length is over 280,000 bytes into a javascript string variable.  when i load the page into netscape the disk spins a really long time, and i end up killing the netscape session.  i'm running netscape 4.05 on SGI IRIX 6.3.   so, is there a maximum string length?  is there a way to work around this?
0
Comment
Question by:clemwang
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Trevor013097
Comment Utility
I read somewhere recently that Javascript has a string limitation of 255 characters although I can't find the documentation at the moment.  It certainly will not take a string of 280,000 bytes (which is 280,000 characters AFAIK).  You could split the string up into smaller chunks but this will give you a lot of small strings and may not be a viable option.  You would then need to rebuild at the point where you use them something like:

(assuming you want to write it to the screen)
document.write(string(1)+string(2)+string(3)......+string(n));

Looking at the line above you could probably write a for..loop to go through all the strings you have.  Possibly even store al the string names in an array.

Trevor.


0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 50 total points
Comment Utility
I have never tried 280.000 bytes but whenever I need a big string, I build it like this - seems to work on quite big strings, definitely more than 256 bytes ;-):

var BigString = 'First part of a really big string';
    BigString += 'Next part of a really big string';
    BigString += 'Next part of a really big string';
....
0
 
LVL 5

Expert Comment

by:Trevor013097
Comment Utility
Michel,

Isn't that method going to give you one string at the end though of 280,000 bytes?

Trevor.


0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Yes, but it seems Netscape can handle this a lot bettter than
var BigString = 'a huge number of bytes in one go.................................';

I have used the above example to generate complete listings of several tens of thousands of bytes - Not 280.000 I admit, but let's see what clemwang replies

Michel
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now