1

In program is 2 structures with string fields. First Structure:

   Private Structure A
       Dim str1 as String 
       Dim str2 as String

Second Structure:

   Private Structure B
       Dim str1 as String 

somewhere in code i assign it to array of

Dim a() as A
Dim b() as B

for Example in A we have name and surname in two string in B name and surname in one in result i need to compare composition of str1 and str2 of a() with str1 b(). in cpp this would be like

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!");
   }
}
6
  • And your question is? Commented Jan 27, 2014 at 10:48
  • And it wouldn't actually be that would it.. because strcmp has a return value that is actually useful. calling strcmp without checking its return value is rather pointless. Commented Jan 27, 2014 at 10:49
  • What do you want to achieve? Commented Jan 27, 2014 at 10:52
  • how to compare string in VB.net may be? I don't understand logic of VB at all) i wrote a question in result i need to compare composition of str1 and str2 of a() with str1 b(). Commented Jan 27, 2014 at 10:52
  • But how compare? you are comparing one A in A with all B in b, so do you want to find equals, or... Commented Jan 27, 2014 at 10:55

3 Answers 3

2

I am not familiar with cpp, however, you can use 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
Sign up to request clarification or add additional context in comments.

3 Comments

o_O my mind is blown. o_O i'm trying to understand it)))
You can use Where comp = 0 if you only want to take the "GOOD".
According to the guidelines, you shouldn't use Compare to check for equality.
1

This is your cpp code translated to VB, with some minor optimizations:

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

7 Comments

how to add a space beetween concat? String.Concat(a(i).str1 ,String.Concat(" ", a(i).str2)
Alternatively: Dim strA = a(i).str1 & " " & a(i).str2
better))) because in real i must concat 3 string and it was awful(but with spaces xD)
You can also use String.Join() if you need a space between every piece. See my updated answer.
found one mistake) if finded exit for to economy time)))
|
0
If (A.str1 + A.str2) = B.str1 Then Debug.Print("GOOD")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.