I am thinking that something is slightly off ... I implemented the code as:
Private Function ReplaceNth(CompleteString As String, occurence As Integer, Find As String, replace As String) As String
Dim CheckOccurence As Integer = 1
Dim NewString As String = CompleteString
While NewString.IndexOf(Find) <> -1
If occurence < CheckOccurence Then
Dim temp As String = CompleteString.Substring(0, CompleteString.Length - NewString.Length)
Return temp.Replace(Find, replace) & NewString
Dim a As Integer = NewString.IndexOf(Find) + Find.Length
NewString = NewString.Substring(a)
CheckOccurence += 1
Return "Not Found"
Dim newProjectFile as new StringBuilder
newProjectFile.append(ReplaceNth(my.computer.FileSystem.ReadAllText(myFile).Replace("COUGAR", "9294653879"), 3,"9294653879","PANTHER")
Then I used My.Computer.FileSyetem.WriteAllText to rewrite modified file
The result I got is:
the 1st,2nd & 3rd instances of COUGAR were changed to 9294653879 and the 4th instance was changed to PANTHER. The desired result is for instances 1st, 2nd and 4th to be changed to COUGAR and the 3rd to be PANTHER. Additionally, since COUGAR was 6 characters long, I need to delete 4 blank spaces after the 2nd instance where COUGAR became 9294653879.
Thanks for any help!