You could use String.Last
Place the following into a code moduleCode:Dim Value As String = "123".AppendIfNeeded("}"c) Console.WriteLine(Value) Console.WriteLine(Value.AppendIfNeeded("}"c))
Of course you could use the single line in the extension method in your code too.Code:<System.Runtime.CompilerServices.Extension()> _ Public Function AppendIfNeeded(ByVal sender As String, ByVal Character As Char) As String Return IIf(sender.Last = Character, sender, String.Concat(sender, Character)).ToString End Function




Reply With Quote