Option Explicit
Private Sub Form_Load()
Dim fso As FileSystemObject
Dim tsReadFile As TextStream
Dim tsWriteFile As TextStream
Dim sRecord As String
Dim sWords() As String
Dim i As Long
Dim bFlag As Boolean
Dim sNewLine As String
Set fso = New FileSystemObject
Set tsReadFile = fso.OpenTextFile("C:\MioFile.txt", ForReading)
Set tsWriteFile = fso.CreateTextFile("C:\NuovoFile.txt")
Do Until tsReadFile.AtEndOfStream
sNewLine = vbNullString
sRecord = tsReadFile.ReadLine
sRecord = Trim$(sRecord)
If sRecord = vbNullString Then
' if line is null, do nothing
Else
sWords = Split(sRecord, Space(1))
For i = 0 To UBound(sWords)
If Len(sWords(i)) = 0 Then
sNewLine = sNewLine & Space(1)
bFlag = True
Else
If bFlag = True Then
sNewLine = sNewLine & " -" & sWords(i)
bFlag = False
Else
sNewLine = sNewLine & sWords(i)
End If
End If
Next
tsWriteFile.WriteLine "-" & sNewLine
End If
Loop
Set fso = Nothing
tsReadFile.Close
tsWriteFile.Close
Set tsReadFile = Nothing
Set tsWriteFile = Nothing
End Sub