jmalcolm
asked on
Saving Long Strings
I've seen similar questions address but I have a specific problem. I want to store a long string to a file (either ADO DB or text file, I don't care), but this string can contain quotation marks and control characters. Is there a simple easy way to do this ?
(Let's say the string can be as long as 64000 characters)
-Jason
(Let's say the string can be as long as 64000 characters)
-Jason
Here is an easy sub routine you can use to setup the string for saving in either a text file or a DB. Just send the string to the routine, and it will return a string ready to be saved in a DB or text file.
Public Function Apostrophe(sFieldString As String) As String
If InStr(sFieldString, "'") Then
Dim iLen As Integer
Dim ii As Integer
Dim apostr As Integer
iLen = Len(sFieldString)
ii = 1
Do While ii <= iLen
If Mid(sFieldString, ii, 1) = "'" Then
apostr = ii
sFieldString = Left(sFieldString, apostr) & "'" & _
Right(sFieldString, iLen - apostr)
iLen = Len(sFieldString)
ii = ii + 1
End If
ii = ii + 1
Loop
End If
strClean = sFieldString
End Function
Public Function Apostrophe(sFieldString As String) As String
If InStr(sFieldString, "'") Then
Dim iLen As Integer
Dim ii As Integer
Dim apostr As Integer
iLen = Len(sFieldString)
ii = 1
Do While ii <= iLen
If Mid(sFieldString, ii, 1) = "'" Then
apostr = ii
sFieldString = Left(sFieldString, apostr) & "'" & _
Right(sFieldString, iLen - apostr)
iLen = Len(sFieldString)
ii = ii + 1
End If
ii = ii + 1
Loop
End If
strClean = sFieldString
End Function
ASKER
Well, what I'm actually looking for is the specifics on how to save a large string, not just convert the Quotation marks. Here's my dilemma..I have huge chunk of text from an rich text control. If I try to save it using the "#write" command, carriage returns, quotation marks, etc. can cause problems when I try to #input it back in. If I try saving it as a binary file, I can #put string easy enough, but to read it back in, must I get it 1 byte at a time? If I try to read in longs then I'll have to bit shift them to get the respective bytes and this is too slow. I'm just looking for an easy (and acceptably fast)way to save and retrieve these big strings.
This may be a little too obvious, but try simply binding the control to a data control.
Create a table in Access that contains a column that is set to store binary data.
Hook this up to your rtf control and *bang*, you information gets stored in the database file whenever the user makes any changes to it.
You can spice this idea up a little bit to actually store and retrieve the information on command whenever you want. You get the idea.
Lankford
ps - I've already done this with a project I am working on it is works great.
Create a table in Access that contains a column that is set to store binary data.
Hook this up to your rtf control and *bang*, you information gets stored in the database file whenever the user makes any changes to it.
You can spice this idea up a little bit to actually store and retrieve the information on command whenever you want. You get the idea.
Lankford
ps - I've already done this with a project I am working on it is works great.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PS - Please note that the Put statement will copy the exact contents of your string to the file, including any special characters and it won't add other characters (unlike, e.g., Print)
ASKER