+ Reply to Thread
Results 1 to 3 of 3

Thread: Period at end of every line

  1. #1
    a8le is offline VB.NET Forum Enthusiast a8le is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Oct 2005
    Posts
    75
    Reputation
    63

    Default Period at end of every line

    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...

    Code:
        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
    Yours Truly,
    Thuan V. Nguyen
    http://www.a8le.com

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    11,032
    Reputation
    1563

    Default

    Lines is already available in Lines property:
    Code:
    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

  3. #3
    a8le is offline VB.NET Forum Enthusiast a8le is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Oct 2005
    Posts
    75
    Reputation
    63

    Default thnx JOHN

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

    Code:
    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts