Imports System
Public Class ReplaceTheLastOccurrence_VB_NET
Public Shared Function replaceTheLastOccurrenceOfACharacterInAString(ByVal str As String, ByVal charToReplace As Char, ByVal replacementChar As Char) As String
Dim pos As Integer = str.LastIndexOf(charToReplace)
If pos <> -1 Then
str = str.Substring(0, pos) & replacementChar & str.Substring(pos + 1)
End If
Return str
End Function
Public Shared Sub Main(ByVal args As String())
Dim str As String = "c++ c python vb java c# php"
Dim charToReplace As Char = "c"c
Dim replacementChar As Char = "W"c
str = replaceTheLastOccurrenceOfACharacterInAString(str, charToReplace, replacementChar)
Console.WriteLine(str)
End Sub
End Class
' run:
'
' c++ c python vb java W# php
'