Skip to content

Instantly share code, notes, and snippets.

@digiguru
Created May 26, 2011 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digiguru/994172 to your computer and use it in GitHub Desktop.
Save digiguru/994172 to your computer and use it in GitHub Desktop.
Replace all data values from an array into a string using jQuery Template markup.
Public Shared Function RenderTemplate(template As String, list As Array) As String
Dim myRegexOptions As RegexOptions = RegexOptions.Multiline
Dim myRegex As New Regex(strRegex, myRegexOptions)
Dim splits = myRegex.Split(template)
Dim matches = myRegex.Matches(template)
Dim i As Integer = 0
Dim swap As Boolean = False
Dim str As New StringBuilder
For Each item In list
swap = False
For i = 0 To splits.Length - 1
If swap Then
str.Append(CallByName(item, splits(i), CallType.Get, Nothing))
Else
str.Append(splits(i))
End If
swap = Not swap
Next
Next
Return str.ToString
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment