?
Solved

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

Posted on 2008-02-08
7
Medium Priority
?
192 Views
Last Modified: 2010-04-30
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.
0
Comment
Question by:blackbookcoder2
  • 3
  • 2
  • 2
7 Comments
 
LVL 38

Assisted Solution

by:PaulHews
PaulHews earned 1520 total points
ID: 20853988
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
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 480 total points
ID: 20854212
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
 

Author Comment

by:blackbookcoder2
ID: 20856025
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 480 total points
ID: 20856201
"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
 

Author Comment

by:blackbookcoder2
ID: 20859418
"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
 
LVL 38

Accepted Solution

by:
PaulHews earned 1520 total points
ID: 20859812
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
 

Author Closing Comment

by:blackbookcoder2
ID: 31429332
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question