Advertisement
datatheoz

Replace Overload For Eazy

May 26th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.57 KB | None | 0 0
  1. Public Function Replace(strText As String, strReplaceWhat As String, replaceWith As Func(Of String)) As String
  2.         Dim i As Integer = strText.IndexOf(strReplaceWhat)
  3.  
  4.         While i <> -1
  5.             strText = strText.Substring(0, i) & replaceWith() & strText.Substring(i + strReplaceWhat.Length)
  6.             i = strText.IndexOf(strReplaceWhat)
  7.         End While
  8.  
  9.         Return strText
  10. End Function
  11.  
  12. Dim s As String = "Hello, my name is #name# and my friend's name is #name#"
  13. s = Replace(s, "#name#", AddressOf RandomName)
  14.  
  15. 'Note: RandomName is your function.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement