Finding substrings within a string

G

Gaston

Sorry if this question seems trivial, but for the life of me, I can'
figure out how to search for something within a string.

Say I got str1="ABC" and str2="AAA AAB AAC ABC ABC"
I want to be able to search str2 and see if str1 exists within it.

Thanks in advanced
 
A

acw

H

Try
str1 = "ABc
str2 = "AAA AAB AAC ABC ABC

MsgBox InStr(1, str2, str1, 1

Ton

----- Gaston > wrote: ----

Sorry if this question seems trivial, but for the life of me, I can'
figure out how to search for something within a string

Say I got str1="ABC" and str2="AAA AAB AAC ABC ABC
I want to be able to search str2 and see if str1 exists within it.

Thanks in advanced
 
R

RickySJr

dim str2 as string
dim str1 as string
dim iplace as integer
dim start as integer
start = 1
iplace = InStr(start,str2,str1)
if iplace = 0 then
'not found
else
' iplace is set the the beginning of the in str2
' where str1 is located
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top