Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have done splitting word by word of textfile

But I want to save each and every word on the original position in original textfile after editing done on that splitted word.


[Edit]Shout removed[/Edit]

What I have tried:

VB
Imports System.IO
Imports System.Security
Imports Microsoft.CSharp

Imports Word = Microsoft.Office.Interop.Word


Public Class Form1
   
    Dim currentword As Integer = 0
    Dim Index1 As Integer = 0
    Dim Index2 As Integer = 0
    Dim line As String
    Dim opp As New OpenFileDialog


    Public Enum Direction
        Up = -1
        Down = 1

    End Enum

    Private Sub RichTextBox1_SelectionChanged(sender As Object, e As EventArgs) Handles DotPadTextBox.SelectionChanged
        Dim fci As Integer = DotPadTextBox.GetFirstCharIndexOfCurrentLine()

        currentline = DotPadTextBox.GetLineFromCharIndex(fci)

        Dim s As String = String.Format("Current line: {0}", currentline)
        Me.Text = s
        Me.BtnUp.Enabled = currentline >= 0

        Me.BtnDown.Enabled = currentline < DotPadTextBox.Lines.Count
    End Sub

    '***********CODE TO SPLIT ,RichTextBox2 LINE INTO WORD****************
    Private Sub DisplayWords(direction As Direction)
        Dim words As String() = Me.RichTextBox2.Lines.SelectMany(Function(line) line.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries)).ToArray()
        Me.TxtCurrentWord.Text = words(currentword)
        Me.TxtPreviousWord.Text = If(currentword > 0, words(currentword - 1), Nothing)
        Me.TxtNextWord.Text = If(currentword < words.Count - 1, words(currentword + 1), Nothing)

        currentword += direction
        If currentword < 0 Then
            If currentword > words.Count - 1 Then
                currentword = words.Count - 1
            End If
        End If
    End Sub



    Private Sub BtnNextWord_Click(sender As Object, e As EventArgs) Handles BtnNextWord.Click
        DisplayWords(Direction.Down)
    End Sub

    Private Sub BtnPrevWord_Click(sender As Object, e As EventArgs) Handles BtnPrevWord.Click
        DisplayWords(Direction.Up)
    End Sub
    '***********CODE ENDS TO SPLIT ,RichTextBox2 LINE INTO WORD****************

    '************CODE TO OPEN FILE*****************
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


        Try
            opp.Filter = "Document Files(*.doc)|*.doc|Document Files(*.docx)|*.docx|Text Files(*.txt)|*.txt|Rtf Files(*.rtf)|*.rtf|HTML Files(*.html)|*.html| AllFiles(*.*)|*.*"


            If opp.ShowDialog() = DialogResult.OK Then
                
                Dim SR As New IO.StreamReader(opp.FileName)
                DotPadTextBox.Text = SR.ReadToEnd()
                
            End If
            
        Catch ex As Exception
            Exit Sub
        End Try

    End Sub
    '************CODE ENDS TO OPEN FILE*****************

    '************CODE TO SAVE FILE*****************
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim saveMe As New SaveFileDialog()
        saveMe.Filter = "Text Documents(*.txt)|*.txt"
        If saveMe.ShowDialog() = Windows.Forms.DialogResult.OK Then
            RichTextBox2.SaveFile(saveMe.FileName, RichTextBoxStreamType.PlainText)
            File.WriteAllLines(saveMe.FileName, DotPadTextBox.Lines)
            MsgBox("File Saved as : " + saveMe.FileName)
        Else
            MsgBox("Failed to pick up file to save as")
        End If

    End Sub
    '************CODE END SAVE FILE*****************

End Class<pre>
Posted
Updated 11-Jul-19 21:17pm
v3
Comments
Richard MacCutchan 12-Jul-19 3:09am    
What is the question?
shaileshshinde 12-Jul-19 3:12am    
QUESTION IS I HAVE SPLITTED LINES INTO WORDS AS CURRENT WORD,PREVIOUS AND NEXT WORD IN TEXTBOXES. AND I HAVE EDITED THAT TEXTBOX CONTENT.
BUT NOW I WANT TO SAVE THAT EDITED WORD ON ORIGINAL PLACE WHICH IT WAS IN FILE.
Maciej Los 12-Jul-19 3:14am    
Do not shout. Using capitals only is rude!
shaileshshinde 30-Aug-19 2:35am    
can you help me in this ?
as i am not getting it how to implement it.please
Richard MacCutchan 12-Jul-19 3:19am    
Then please explain what is not working and where in your code the problem occurs.

1 solution

I've provided instruction how to achieve that in the comment to your previous question[^].

You can't expect that we solve all your issues by providing complete and "working" code. You have to do something if you want to learn.
 
Share this answer
 
Comments
shaileshshinde 13-Jul-19 3:49am    
ok
shaileshshinde 24-Jul-19 4:00am    
can anyone help me with the solution as i am not getting the idea for implementation?

this is the last query in my project.otherwise my complete project is ready.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900