在程序中是带有字符串字段的2个结构。 第一种结构:
Private Structure A
Dim str1 as String
Dim str2 as String
第二结构:
Private Structure B
Dim str1 as String
代码中的某处我将其分配给
数组Dim a() as A
Dim b() as B
对于A中的示例,我们在两个字符串中有名称和姓氏 在B名和姓氏中 结果我需要比较a1的str1和str2的组成与str1 b()。 在cpp这将是
for(int i = 0; i < sizeA; i++)
{
for(int j = 0; j < sizeB;i++)
{
if(!(strcmp(strcat(a[i].str1,a[i].str2),b[j].str1)) printf("GOOD!");
}
}
答案 0 :(得分:2)
我不熟悉cpp,但是,你可以使用LINQ:
Dim comparisons = From a1 In a
From b1 In b
Let a1Concat = a1.str1 & a1.str2
Let comp = String.Compare(a1Concat, b1.str1)
' you can enumerate the query with a For-Each '
For Each result In comparisons
Dim a1Str1 As String = result.a1.str1
Dim a1Str2 As String = result.a1.str2
Dim a1Concat As String = result.a1Concat
Dim b1Str1 As String = result.b1.str1
Dim comparison As Int32 = result.comp
Next
答案 1 :(得分:1)
这是你的cpp代码翻译成VB,有一些小的优化:
For i = 0 To (a.Length - 1)
Dim strA = String.Join(" ", a(i).str1, a(i).str2)
For j = 0 To (b.Length - 1)
Dim strB = b(j).str1
If String.Equals(strA, strB, StringComparison.Ordinal) Then
Console.WriteLine("GOOD")
End If
Next
Next
答案 2 :(得分:0)
If (A.str1 + A.str2) = B.str1 Then Debug.Print("GOOD")