3 Replies - 679 Views - Last Post: 01 September 2013 - 09:00 AM Rate Topic: -----

#1 alexandru292  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-September 13

[Problem] Open file text, delete line and new text line VB.NET

Posted 01 September 2013 - 07:57 AM

Hi,

I have a big problem with a project code, let me explain in more detail.

Have 15 line in "C:\TEXT.txt":
line1
line2
line3
line4
line5
line6
line7
line8
line9
line10
line11
line12
line13
line14
line15


The question is, how do I make in vb.net 2010 for search in "C:\TEXT.txt" and how to find line10, delete this line and add new text in this line?

Thanks,
Alex

Is This A Good Question/Topic? 0
  • +

Replies To: [Problem] Open file text, delete line and new text line VB.NET

#2 Michael26  Icon User is online

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,534
  • Joined: 08-April 09

Re: [Problem] Open file text, delete line and new text line VB.NET

Posted 01 September 2013 - 08:32 AM

Some code would be nice. You use streamReader to read text, store it into List of string, locate text you need to delete, remove that value from the list and use StreamWriter to write text to the file.
Was This Post Helpful? 0
  • +
  • -

#3 alexandru292  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-September 13

Re: [Problem] Open file text, delete line and new text line VB.NET

Posted 01 September 2013 - 08:50 AM

View PostMichael26, on 01 September 2013 - 08:32 AM, said:

Some code would be nice. You use streamReader to read text, store it into List of string, locate text you need to delete, remove that value from the list and use StreamWriter to write text to the file.


Hi Michael26, thanks for your reply!

I have this code for add line in text file:
        Using sw As New StreamWriter(LocalAppData & " \.minecraft\launcher_profiles.json")


            sw.WriteLine("{")
            sw.WriteLine("  " & Chr(34) & "profiles" & Chr(34) & ": {")
            sw.WriteLine("    " & Chr(34) & "Forge" & Chr(34) & ": {")
            sw.WriteLine("      " & Chr(34) & "name" & Chr(34) & ":" & Chr(34) & "Forge" & Chr(34) & ",")
            sw.WriteLine("      " & Chr(34) & "lastVersionId" & Chr(34) & ": " & Chr(34) & "1.6.2-Forge9.10.0.845" & Chr(34))
            sw.WriteLine(Chr(34) & "selectedProfile" & Chr(34) & ":" & Chr(34) & "Forge" & Chr(34) & ",")
            sw.WriteLine("    },")


            For Each line As String In lines
                sw.WriteLine(line)

            Next



But the problem is next, this code add:
line1 - correctly
line2 - correctly
line3 - correctly
line4 - correctly
line10 - incorrect
line5
line6
line7
line8
line9
-here must add line10-



Thanks,
Alex
Was This Post Helpful? 0
  • +
  • -

#4 Michael26  Icon User is online

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,534
  • Joined: 08-April 09

Re: [Problem] Open file text, delete line and new text line VB.NET

Posted 01 September 2013 - 09:00 AM

This is the StreamWriter where is the stream reader?
I already said what you need to do, break it down step by step

1. use streamReader to read text,
2. store it into List of string,
3. locate text you need to delete(in the list),
4. remove that value from the list(in the list),
5. and use StreamWriter to write the updated text to the file.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1