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 ?
Printable View
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 ?
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
Well, I don't know if my solution is shorter than your "painfully long" one, but check my answer to another post.
------------------
Marty
Why is it called lipstick if you can still move your lips?
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:
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.Code: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
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
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?