あなたの質問から私が理解したことに基づいて、これがあなたが求めているものです。調整する必要がある場合は、お気軽にコメントしてください。
Private Sub Question1()
Dim list = File.ReadAllLines("yourFilePath").ToList()
Dim itemCount = list.Count
For i As Integer = 0 To itemCount - 1
If list(i) = "//This Line" AndAlso Not ((i + 1) > itemCount) Then
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 As List(Of String))
For Each item As String In items.Where(Function(listItem) listItem <> "//This Line") ' Exclude redundant text
Dim processes = Process.GetProcessesByName(item)
For Each process As Process In processes
Try
process.Kill()
Catch
' Do your error handling here
End Try
Next
Next
End Sub
更新: 以下のコードは、以下のコメントで要求された変更を反映する更新バージョンです。
Private Sub Question1()
Dim list = File.ReadAllLines("YourFilePath").ToList()
Dim itemCount = list.Count
For i As Integer = 0 To itemCount - 1
If list(i) = "//This Line" Then
If (i + 1 > itemCount - 1) Then ' Check if the current item is the last one in the list, if it is then add the text to the list
list.Add(TextBox1.Text)
Else ' An item exists, so just update its value
list(i + 1) = TextBox1.Text
End If
End If
Next
' Write the list back to the file
File.WriteAllLines(Application.StartupPath & "\test.txt", list)
KillProcesses(list)
End Sub