我有一个带有以下值的变量:
Variable1 = "Apple, Banana, Pineaple, Grape, Coconut"
我想使用Replace
获得以下结果:
VariableX = "<span class="text1">Apple</span> <span class="text2">Banana</span> <span class="text1">Pineapple</span> <span class="text2">Grape</span> <span class="text1">Coconut</span>"
因此,第一个值获得text1
,第二个获得text2
,第三个获得text1
,第四个获得text2
,依此类推,直到结束。< / p>
答案 0 :(得分:1)
' Split into an array...
a = Split(Variable1, ",")
' Add each element to a <span> tag...
For i = 0 To UBound(a)
VariableX = VariableX & "<span class=""text" & i + 1 & """>" & Trim(a(i)) & "</span>"
Next
关于评论的更新:
要在两个值之间切换,您可以将它们放在一个数组中,然后使用Mod
来选择其中一个值。
a = Split(Variable1, ",")
strClasses = Array("text-info", "text-warning")
' Add each element to a <span> tag...
For i = 0 To UBound(a)
VariableX = VariableX & "<span class=""" & strClasses(i Mod 2) & """>" & Trim(a(i)) & "</span>"
Next