|
-
Feb 10th, 2022, 11:19 PM
#1
Thread Starter
New Member
Remove Line From Text File
-
Feb 10th, 2022, 11:50 PM
#2
Re: Remove Line From Text File
Try this...
Code:
Dim lines As New List(Of String)(IO.File.ReadAllLines("barcode.txt"))
lines.RemoveAll(Function(l) l.Contains(TextBox2.Text))
TextBox1.Lines = lines.ToArray
Edit: Actually, I missed the purpose of TextBox1. The first two lines in my code removes the lines you specify in TextBox2. After that you should save lines back to your file, and probably reload your grid...
Last edited by .paul.; Feb 11th, 2022 at 12:03 AM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 11th, 2022, 12:20 AM
#3
Re: Remove Line From Text File
You can do this in one line if you want:
vb.net Code:
File.WriteAllLines(filePath, File.ReadAllLines(filePath).Where(Function(line) Not line.Contains(TextBox2.Text)))
-
Feb 11th, 2022, 02:14 AM
#4
Thread Starter
New Member
Re: Remove Line From Text File
 Originally Posted by jmcilhinney
You can do this in one line if you want:
vb.net Code:
File.WriteAllLines(filePath, File.ReadAllLines(filePath).Where(Function(line) Not line.Contains(TextBox2.Text)))
Thanks you
how to implementation this in my program?
it's just edit "filepath" with my txt file?
-
Feb 11th, 2022, 02:25 AM
#5
Re: Remove Line From Text File
I wouldn't recommend doing that in one line, as you also want to reset TextBox1.Lines before saving lines to "barcode.txt"
How you refer to "barcode.txt" depends on where it is in relation to your executable
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 11th, 2022, 02:30 AM
#6
Re: Remove Line From Text File
I think I may have misunderstood what you want to do but I can't really see what the purpose of TextBox1 is. Are you saying that you want to remove just the line displayed in TextBox1 if it contains the text displayed in TextBox2?
-
Feb 11th, 2022, 04:02 AM
#7
Thread Starter
New Member
Re: Remove Line From Text File
 Originally Posted by jmcilhinney
I think I may have misunderstood what you want to do but I can't really see what the purpose of TextBox1 is. Are you saying that you want to remove just the line displayed in TextBox1 if it contains the text displayed in TextBox2?
yes, this is i want
-
Feb 11th, 2022, 04:03 AM
#8
Thread Starter
New Member
Re: Remove Line From Text File
 Originally Posted by .paul.
I wouldn't recommend doing that in one line, as you also want to reset TextBox1.Lines before saving lines to "barcode.txt"
How you refer to "barcode.txt" depends on where it is in relation to your executable
thank you, i appreciate it
-
Feb 11th, 2022, 09:22 PM
#9
Re: Remove Line From Text File
So how do you get the line in TextBox1 in the first place? It looks like you have a scrollbar in the screen shot. Is it a multiline TextBox that contains the entire file but it's only tall enough to show one line at a time? Please provide a FULL and CLEAR explanation of the problem.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|