Click to See Complete Forum and Search --> : format text when saving to a file
let's say I got a 5 MB long string in memory.
I want to save it as a file with no more that 65 bytes per line.
looping sounds horrible...it takes so much time
is there a function doing this ?
badgers
Jan 26th, 2000, 12:30 AM
when you say 65 bytes per line, do you mean with word wrapping?
yes that's what I mean
I can loop with the mid function but it's painfully long; I wonder if there is a function writing to a file and wrapping in function of a parameter
MartinLiss
Jan 26th, 2000, 01:12 AM
Well, I don't know if my solution is shorter than your "painfully long" one, but check my answer (http://www.vb-world.net/ubb/Forum1/HTML/013155.html) to another post.
------------------
Marty
Why is it called lipstick if you can still move your lips?
Aaron Young
Jan 26th, 2000, 01:39 AM
Here's a possible Solution I came up with, it uses the CopyMemory API to Transfer the String into an Array of User Types Each Containing an Array of 65 Bytes, which automatically and Very quickly segments the string into 65 Byte Portions which you can then output to a File:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type MemStringType
sString(64) As Byte
End Type
Private Sub OutputFile(ByVal FileName As String, ByVal Data As String)
Dim tStrings() As MemStringType
Dim iFile As Integer
Dim iIndex As Long
ReDim tStrings(Len(Data) / 65)
CopyMemory tStrings(0), ByVal Data, LenB(tStrings(0)) * UBound(tStrings)
iFile = FreeFile
Open FileName For Output As iFile
For iIndex = 0 To UBound(tStrings)
Print #iFile, StrConv(tStrings(iIndex).sString, vbUnicode)
Next
Close iFile
End Sub
Private Sub Command1_Click()
OutputFile "C:\TheFile.txt", sTheBig5MBString
End Sub
I tested this passing it a String of 5 Million "A"'s equivalent to 5MB of Data and it took only a matter of seconds.
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com
MartinLiss
Jan 26th, 2000, 01:50 AM
When yaz said "no more that 65 bytes per line", I assumed he meant that he wanted to break the lines at the end of words.
------------------
Marty
Why is it called lipstick if you can still move your lips?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.