Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search a group of string in another group of string 1

Status
Not open for further replies.

YanaD

Programmer
Mar 22, 2001
38
0
0
US
I need to search for a group of string in the other group of string, and if it's find it, don't write that search string into the other string. ex: MySearch = "05,02,07",
SearchIn "02,04,05,08,07". So I need to search and see if 05 exists in 'SearchIn,if exists then don't continue to write in the SearchIn string, If not exists then continue to write 05 into SearchIn string placing , after 07. And so on so on.
Please help ASAP.
 
I don't think I understand the question clearly. Have you tried the Instr() function provided by VB? Are you trying to parse out 05, 02, and 07 to search in the SearchIn string? Can you rephrase the question of give another example or maybe someone else will understand.

Thanks
 
You probably want to use a combination of split and inst.

First, Split the first string into single elements

Dim arElements as Variant

- Split the search string up
srElements = Split(MySearch , ",")

'' Loop for each search string
for i = 0 to ubound(arElements)
IF instr( arElements(i), SearchIn ) then
'' Don't do anything as the string has been found
ELSE
Searchin = SearchIn & "," & arElements(i)
END IF
NEXT i

Hope this helps,

Chris Dukes
 
Dear, Chris! Thank you a million.
I paste it into my programm, but the thing is that if its find the Searched string it goes to Else and write it down to the existing string, I can't solve it. But it splits the string, that what i was looking for. So if you will see why it goes to ELSE, please write me down.
Thanx again.
 
Try

IF instr(1, SearchIn, arElements(i), vbTextCompare ) = 0 then

I was doing it from memory so could not remember the exact syntax.

Instr Check the existance of the second string in the first string, but I got it the wrong way around,

Chris Dukes
 
Yes, I found it myself, then it worked.
Anyways thanx a million.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top