Period at end of every line

a8le

Well-known member
Joined
Oct 27, 2005
Messages
75
Programming Experience
5-10
I am in need of a way to put a period at the end of every line in any document but the output will always be a text document.

So this is my plan...

1) Put a multiline textbox on form available for copy and paste of content from original file.
2) On button click... Use regex to find end of line ($) then add a period directly after it.
3) Loop through until end of file.
4) Once done a "save file dialog" should pop up asking where to save the text file.

So far I am only able to do step 1, I need a little help with steps 2-4. I have tried the following but it doesn't work...

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oFile As System.IO.File
        Dim oWrite As System.IO.StreamWriter
        Dim Needy As String = tbx_main.Text
        Dim Added As String = Regex.Replace(Needy, "(\p{P})(?=\Z|\r\n)", ".")
        oWrite.Write(Added)
        oWrite.Close()
        oWrite = oFile.CreateText("C:\Text_to_Speech.txt")
    End Sub

What you are looking at is my misguided attempt at this. Please point me in the right direction.

-Thuan
 
Lines is already available in Lines property:
VB.NET:
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles SaveFileDialog1.FileOk
    Using writer As New StreamWriter(Me.SaveFileDialog1.FileName, False)
        For Each line As String In Me.TextBox1.Lines
            writer.WriteLine(line & ".")
        Next
    End Using
End Sub
 
thnx JOHN

Its been a while so I but I got everything working right with this...

VB.NET:
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
oMyStream = saveFileDialog1.OpenFile()
Dim oWrite As New StreamWriter(oMyStream)
For Each LineInput As String In tbx_main.Lines
‘Core Code, add periods to beginning or end
If rbtn_begin.Checked = True Then
‘Beginning
oWrite.WriteLine(tbx_desired.Text + LineInput)
ElseIf rbtn_end.Checked = True Then
‘End
oWrite.WriteLine(LineInput + tbx_desired.Text)
End If
Next
oWrite.Close()
End If

Thanks again, Thuan.
 
Back
Top