Dim Data1 As String
Dim Data2 As String
Dim sFinal As String
Dim sLeft As String
Dim sRight As String
Dim quote As String
quote = """"
Data1 = rtb.SelectedText 'original string
Data2 = "<font color=" + quote + codenumber + quote + ">" 'string to insert
sLeft = Microsoft.VisualBasic.Left(Data1, Len(Data1) - rtb.SelectionStart + rtb.SelectionLength) 'get the left section before insert
sRight = Microsoft.VisualBasic.Right(Data1, rtb.SelectionLength) 'get right section after insert
sFinal = sLeft & Data2 & sRight 'make new string of left & middle & right
rtb.SelectedText = sFinal + "</font>"
I want to insert <font color="#fontcode"> before the selected text in rtb(richtextbox) and </font> at the end of the selected text. This code adds the <font....> for only 3 characters from right. Please let me know what mistake i am making. Thank you