1

我有 2 个列表框。listbox1 包含可变帐户名称,

John
James
Matt

第二个列表框包含一个非变量脚本

Dear <account name>
Thank you for contacting us.
We will get back to you soon.

我将遍历帐户名称。我有那个代码。但是我怎样才能在下面的第三个列表框或文本框中获得输出;

Dear John
Thank you for contacting us.
We will get back to you soon.

Dear James
Thank you for contacting us.
We will get back to you soon.

Dear Matt
Thank you for contacting us.
We will get back to you soon.
4

1 回答 1

1

我不确定您为什么要为静态文本使用 ListBox,但是此代码应该可以执行您希望它执行的操作。我For Each用来遍历两个列表框的对象集合,将结果对象转换为字符串,然后将修改后的行添加到 List(Of String),然后将其分配给 TextBox 的 Lines 属性。看看这是否适合你。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim result As List(Of String) = New List(Of String)
    For Each item As Object In ListBox1.Items
        For Each line As Object In ListBox2.Items
            result.Add(CStr(line).Replace("<account name>", CStr(item))) 'Modify line and add to List
        Next
        result.Add("") 'Add seperator
        TextBox1.Lines = result.ToArray() 'Have to convert to String Array since that is what Lines is
    Next
End Sub
于 2013-10-20T02:20:08.053 回答