Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text manipulation question 2

Status
Not open for further replies.

Almarton

Programmer
Jan 1, 2002
42
0
0
BR
Hi All;

I got a text file that comes like:

"1Name";"LastName";"Comment field this one extends itself
and breaks in two lines"
"2Name";"LastName";"Shorter comment now"


... and it goes.

This sample is somewhat like an export txt from Outlook Express, the problem is that when the comment field splits in two lines Oultook cannot mount back the information correctly when re-importing the txt cause it mistakes the broken line. What I need is a code to read the txt file and whenever it breaks lines without closing the quotes first it gets everything and rewrites it on another one formating like below:



"1Name";"LastName";"Comment field this one extends itself and breaks in two lines"
"2Name";"LastName";"Shorter comment now"






Alexandre @lmarton Marton
almarton@task.com.br
 
Try it with

replace(CommentFieldText,Chr(11)," ")



peterguhl@yahoo.de
 
excause me it was wrong
that's the right version

Replace(Text1(3).Text, Chr(13) & Chr(10), Chr(32))



peterguhl@yahoo.de
 
Sorry but It does not help a bit!

String manipulation is not main the question, string condition detection is.

I don't know how write the routine to read the file (as a stream ?!? ) and worse: to identify when the line being broken whithout having closed de quotes first and uppon detecting that condition to rewrite the entire line joining the parts in another file...

but thanks for the try anyway...

Alexandre @lmarton Marton
almarton@task.com.br
 
Here is the code to do this with some explanation.
___
[tt]
Dim fIn As Integer, fOut As Integer
Dim S As String

'open the i/p file
fIn = FreeFile
Open "C:\input.txt" For Input As #fIn
'open the o/p file
fOut = FreeFile
Open "C:\output.txt" For Output As #fOut

'scan thru the i/p file
Do Until EOF(fIn)
'read full line
Line Input #fIn, S
'remove spaces (optional)
S = Trim$(S)
'if not a blank line
If Len(S) Then
'write it to o/p file on the current line
Print #fOut, S;
'if the comment is complete (" on right)
If Right$(S, 1) = """" Then
'start a new line
Print #fOut,
'otherwise
Else
'append a space to the current line
Print #fOut, " ";
End If
End If
Loop
'close the i/o files
Close #fIn, #fOut
[/tt]
 
If I understand correctly try somthing like this:

' Declare Variables
Dim InputData As String
Dim TempString As String
Dim StringComplete As Boolean
' Initialize Variables
StringComplete = False
TempString = vbNullString
' Open files to work with
Open "C:\Test.txt" For Input As #1
Open "C:\Testout.txt" For Output As #2
'Loops through the file until EOF is True
Do Until EOF(1)
Line Input #1, InputData
' Tests to see if the string ends in a quote
If Right$(InputData, 1) <> &quot;&quot;&quot;&quot; Then
TempString = TempString & InputData
Else
TempString = TempString & InputData
StringComplete = True
End If
' Tests to see if the string is complete
If StringComplete = True Then
Print #2, TempString
TempString = vbNullString
StringComplete = False
End If
Loop
Close
MsgBox &quot;Done!&quot;, vbInformation

Swi
 
Swi

You keep solving all my troubles man!
From yesterday to today 2 out of 2.

You just gave me the E-X-A-C-T solutions on both
cases.

Thanks a lot and you rule man....





Alexandre @lmarton Marton
almarton@task.com.br
 

Hypetia, I've got to do justice to u also your answer also suits me perfectly thank you both guys I'm in debt.

@lmarton (BRAZIL)

Alexandre @lmarton Marton
almarton@task.com.br
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top