AddLeftIfDoesntExist
Adds a value onto the beginning of a string if it does not already exist there.
Source
''' <summary>
''' Adds a value onto the beginning of a string if it does not already exist there.
''' </summary>
''' <param name="buf"></param>
''' <param name="value"></param>
''' <returns></returns>
''' <remarks></remarks>
<Extension()> _
Public Function AddLeftIfDoesntExist(ByVal buf As String, ByVal value As String) As String
If buf.Length < value.Length Then
Return buf
End If
If buf.Left(value.Length) = value Then
Return buf
Else
Return value & buf
End If
End Function
Example
Dim buf As String = "Blake"
buf = buf.AddLeftIfDoesntExist("*")
MsgBox(buf)