Function modify a letter in a string Learn programming Visual Basic (




Function modify a letter in a string


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");


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

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.