vb6 select a string within a string using two arrays and copy the selection to the third array

vb6 select a string within a string using two arrays and copy the selection to the third array.
This question has two parts, 500 pts will be awarded to whomever answers both parts

I have two arrays:

Dim arrA(0) as string
Dim arrB(0) as string
Dim arrC(0) as string
Dim arrD(0) as string

arrA(0)  = "This is a test for me to find the answer?Please select the correct one."
arrB(0) = "find the answer?"
arrC(0) = ""
arrD(0) = ""

Part 1
how can I select the wording in arrB(0) out of arrA(0) and copy the selection to arrC(0)?


Part 2
How can I copy the question mark, character of the string "?", to a fourth array?
 
Thanks in advance.
blackbookcoder2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PaulHewsCommented:
Can you post what arrC and arrD values would be after the desired operations?  Is the value of arrA supposed to change?

arrA(0)  = "This is a test for me to find the answer?Please select the correct one."
arrB(0) = "find the answer?"
arrC(0) = ?
arrD(0) = ?
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
I agree with Paul...it's unclear what you are after.  Please give some DETAILED examples.

I think you want to REMOVE the value of "B" from "A" and place the result into "C"?

        Dim arrA(0) As String
        Dim arrB(0) As String
        Dim arrC(0) As String
        Dim arrD(0) As String

        arrA(0) = "This is a test for me to find the answer?Please select the correct one."
        arrB(0) = "find the answer?"
        arrC(0) = ""
        arrD(0) = ""

        arrC(0) = Replace(arrA(0), arrB(0), "")
        arrD(0) = Right(arrB(0), 1)

        Debug.Print arrA(0)
        Debug.Print arrB(0)
        Debug.Print arrC(0)
        Debug.Print arrD(0)

Producing this output:

    This is a test for me to find the answer?Please select the correct one.
    find the answer?
    This is a test for me to Please select the correct one.
    ?
0
blackbookcoder2Author Commented:
excuse me for the unclear question.  I want to know if ArrB(0) contents are found anywhere is ArrA(0) and if it is found in ArrA(0) copy the content fragment of ArrA(0) to a new array.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Mike TomlinsonMiddle School Assistant TeacherCommented:
"I want to know if ArrB(0) contents are found anywhere is ArrA(0)"

That is simply:

        If InStr(arrA(0), arrB(0)) > 0 Then
            Debug.Print "arrB(0) is present in arrA(0)"
        End If

"and if it is found in ArrA(0) copy the content fragment of ArrA(0) to a new array"

What is the point of copying the fragment from arrA(0)?  The fragment from arrA(0) must be the same as arrB(0)...otherwise you wouldn't have a match right?!  So copying it to another array is as simple as copying arrB(0):

    arrC(0) = arrB(0)
0
blackbookcoder2Author Commented:
"I want to know if ArrB(0) contents are found anywhere is ArrA(0)", how can i use mid to copy the string from ArrA(0) to another variable?
0
PaulHewsCommented:
As Idle_Mind suggested, you could just copy the B variable... but this is how you would use Mid$
Option Explicit
 
Private Sub Command1_Click()
    Dim arrA(0) As String
    Dim arrB(0) As String
    Dim arrC(0) As String
    Dim arrD(0) As String
    
    arrA(0) = "This is a test for me to find the answer?Please select the correct one."
    arrB(0) = "find the answer?"
    arrC(0) = ""
    arrD(0) = ""
    
    Dim lngPos As Long
    lngPos = InStr(1, arrA(0), arrB(0))
    If lngPos > 0 Then
        arrC(0) = Mid$(arrA(0), lngPos, Len(arrB(0)))
        
    End If
    MsgBox arrC(0)
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
blackbookcoder2Author Commented:
Thanks both of you for your help, paulHews And IdleMind.  I know it was an unclear question, my apologies.  The mid solution is what I was looking for.  Copying arrC(0) = arrB(0) will only work one time in the programming I am working on.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.