VB.Net - 如何用文本中的另一个数组替换数组

时间:2013-02-04 13:13:53

标签: vb.net

我一直在寻找,我发现了一些类似的问题,但没有一个是我的解决方案,所以我需要的是Visual Basic:

我有一个文本(string),我有两个像这样的数组:

Dim data_array_one As String() = {"One", "Two", "Three", "Four"}
Dim data_array_two As String() = {"Five", "Six", "Seven", "Eight"}

我需要的是在“ Five ”的文本中替换每个“ One ”,每个“ Two ”替换“六个“等...... 我一直在使用简单的替换功能:

text1 = text1.Replace("One", "Five")
text1 = text1.Replace("Two", "Six")
...

但是现在数组包含24个元素,并且每天它会自动递增,所以我需要一些东西来自数组而不是实际的方式... 谢谢你提前。

1 个答案:

答案 0 :(得分:1)

您可以尝试将此作为一种简单的解决方法。

dim i as single

For i = 0 to data_array_one.getlength(0)
text1 = text1.Replace(data_array_one(i), data_array_two(i))
next

然而,效率并不高,正如托卡文在对你的问题的评论中所说,这可能会导致“四”在“十四”中被替换的问题。