Function modify a letter in a string Learn programming Visual Basic (VB.net)

Lesson:

Functions


Exercise:

Function modify a letter in a string 10


Objetive:

Create a function named "ChangeChar" to modify a letter in a certain position (0 based) of a string, replacing it with a different letter:

string sentence = "Tomato";
ChangeChar(ref sentence, 5, "a");


Code:

Imports System
Public Class exercise110
    Public Shared Sub ChangeChar(ByRef text As String, ByVal position As Integer, ByVal letter As Char)
        text = text.Remove(position, 1)
        text = text.Insert(position, letter.ToString())
    End Sub

    Public Shared Sub Main()
        Dim sentence As String = "Tomato"
        ChangeChar(sentence, 5, "a"c)
    End Sub
End Class