I'm writing a string replacing function to replace smiles with there actual image location but the code is going to be very big and messy because of all the nested ifs but i cant think of a more efficient way of writing the code.
Public Function exchangeSmilies(ByVal postString As String) As String Dim ChangedString = postString ChangedString.ToLower() If ChangedString.Contains(":)") Then ChangedString = ChangedString.Replace(":)", GetSmilieMapPath("smile.gif")) If ChangedString.Contains(":p") Then ChangedString = ChangedString.Replace(":p", GetSmilieMapPath("toungue.gif")) If ChangedString.Contains(";)") Then ChangedString = ChangedString.Replace(";)", GetSmilieMapPath("wink.gif")) If ChangedString.Contains("<3") Then ChangedString = ChangedString.Replace("<3", GetSmilieMapPath("heart.gif")) End If End If End If End If Return ChangedString End Function Public Function GetSmilieMapPath(ByVal SmilieImage As String) As String GetSmilieMapPath = "<img src=" & Chr(34) & "../Images/Smilies/" & SmilieImage & Chr(34) & ">" Return GetSmilieMapPath End Function
<3but not:, your code won't do any replacements. Start by un-nesting all these if's. Then if it still looks messy, try the dictionary approach other answers suggest.