joecool2005 Posted April 12, 2007 Share Posted April 12, 2007 Hi,I have a really big string inside a variable "data".When I did Response.Write(data), I was able to display all the string.But when I did objFile.WriteLine(data) to a file, I was not able to write all the string in the file. It was truncated.Why?What should I do?Thx Link to comment Share on other sites More sharing options...
Yahweh Posted April 12, 2007 Share Posted April 12, 2007 Hi,I have a really big string inside a variable "data".When I did Response.Write(data), I was able to display all the string.But when I did objFile.WriteLine(data) to a file, I was not able to write all the string in the file. It was truncated.Why?What should I do?ThxOdds are, there is some kind of buffer limit, probably 64kb, that you can write to a text file at any given time. If that is the case, then the simple solution to your problem is writing your data is smaller chunks, rather than all at once. You can split your data into fixed-sized chunks using a simple regular expression, then you can write your data chunk by chunk as you loop through the matches collection:Dim regex, match, matches 'regex variablesdim fs, f 'text file vars'creating a text fileset fs=Server.CreateObject("Scripting.FileSystemObject") set f=fs.CreateTextFile(Server.Mappath(someFileName),true) 'create regexp object and set properties set regex = new regexp regex.IgnoreCase = True regex.Global = True regex.Pattern = "[\s\S]{1,10000}" 'matches *at most* 10000 characters at a time 'I'm using "[\s\S]" rather than "." as a convenient way to match newline characters. 'Create matches collection to parse data into managable 10000-character chunks Matches = regex.Execute(data) 'Loop through matches collection for each match in matches 'writing each chunk to the file f.write(Match.Value) nextf.close'cleaning upset regexp = nothingset f=nothingset fs=nothing Link to comment Share on other sites More sharing options...
joecool2005 Posted April 13, 2007 Author Share Posted April 13, 2007 Hi,Thanks for your help.I try to execute your code and I have an error on this lineMatches = regex.Execute(data)It says "Wrong number of arguments or invalid property assignment "My data contains a long XML string and there is no newline.thx Link to comment Share on other sites More sharing options...
pulpfiction Posted April 13, 2007 Share Posted April 13, 2007 Try this... dim str, slt' some sample textstr = "With ASP you can dynamically edit, change or add any content of a Web page, respond to data submitted from HTML forms, access any data or databases and return the results to a browser, customize a Web page to make it more useful for individual users"dim st, i, size' Mention number of characters to splitsize = 10i = 0st = 1while st<=len(str) slt = Mid(str, st, size) st = st + size i = i + 1 response.write(slt) response.write("<br />")wend Link to comment Share on other sites More sharing options...
Yahweh Posted April 15, 2007 Share Posted April 15, 2007 Hi,Thanks for your help.I try to execute your code and I have an error on this lineMatches = regex.Execute(data)It says "Wrong number of arguments or invalid property assignment "My data contains a long XML string and there is no newline.thxOops, that should have said:Set Matches = regex.Execute(data) Matches is an object, so you have to use "Set" with it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now