VB.NET Replace Lines & Task Killer -


i have 2 questions vb.net project codded on .netframework 4.0

1: example have text file "textfile1.txt" program need find line "//this line" , replace next line after "//this line"

example: in textfile1.txt

//this line code here 

i need replace code here text textbox1.text

2: have text file "multilinetextbox1" program need kill process name multitextbox1 line line

example: in multilinetextbox1

notepad mspain 

notepad , mspaint need killed...

base on understood question after. if there adjustments make feel free comment.

private sub question1()     dim list = file.readalllines("yourfilepath").tolist()     dim itemcount = list.count      integer = 0 itemcount - 1         if list(i) = "//this line" andalso not ((i + 1) > itemcount)             list(i + 1) = textbox1.text         end if     next      killprocesses(list) end sub  private sub question2()     dim list = textbox1.text.split(new string() {environment.newline}, stringsplitoptions.none).tolist()     killprocesses(list) end sub  private sub killprocesses(items list(of string))     each item string in items.where(function(listitem) listitem <> "//this line") ' exclude redundant text         dim processes = process.getprocessesbyname(item)          each process process in processes             try                 process.kill()                                      catch                 ' error handling here             end try         next     next end sub 

update: code below updated version reflect changes requested in comments below

private sub question1()     dim list = file.readalllines("yourfilepath").tolist()     dim itemcount = list.count      integer = 0 itemcount - 1         if list(i) = "//this line"             if (i + 1 > itemcount - 1) ' check if current item last 1 in list, if add text list                 list.add(textbox1.text)             else ' item exists, update value                 list(i + 1) = textbox1.text             end if         end if     next      ' write list file     file.writealllines(application.startuppath & "\test.txt", list)      killprocesses(list) end sub 

Comments