|
-
Oct 27th, 2022, 11:20 AM
#1
Thread Starter
Addicted Member
VB.net Append text in the end of txt file
Hello, can someone advice me how i can make correct to add new value string in text file at specific location.
I will give full example
So let's start i have a file File1.txt
Inside i have this information:
Line1: /grant Username2 OI)(CI)F /T
Line2: /GRANT:Username2,Full /UNLIMITED
so what i want to do programatically, in Line 1 i want to add after /T new record string
example result will be:
Code:
/grant Username2:(OI)(CI)F /T /grant Username3:(OI)(CI)F /T
then for line 2 i want to add before the /UNLIMITED new string
example result will be:
/GRANT:Username2,Full /GRANT:Username3,Full /UNLIMITED
how i can make it like that? - Please note Username are just example text it can be other text
And for example how can i add new line in the end with string after line2, to add new strings each line if i need?
Last edited by luckydead; Oct 27th, 2022 at 12:11 PM.
-
Oct 27th, 2022, 08:37 PM
#2
Re: VB.net Append text in the end of txt file
Your title says:
Append text in the end of txt file
but your post says:
add new value string in text file at specific location
It would be helpful if your post didn't contradict your thread title.
-
Oct 27th, 2022, 08:41 PM
#3
Re: VB.net Append text in the end of txt file
You can't really insert text into a file at an arbitrary point. You need to read the file, process the data as appropriate, then write all the data back to the file. You can call File.ReadAllLines to read the file into a String array. You can then modify any element of the returned array however you want; each one is just a String. You can then call File.WriteAllLines to write the array back to the file.
If you want to add new lines at the same time, you can create a new List(Of String) and populate that from the array. You can then add, edit and remove lines as desired before passing the List to WriteAllLines.
Before you ask, no I won't provide an "example", which really means write your code for you. I'm prepared to help further but I would expect to see an attempt to implement the advice already provided first.
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
|