ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Finding substrings within a string (https://www.excelbanter.com/excel-programming/289916-finding-substrings-within-string.html)

Gaston[_6_]

Finding substrings within a string
 
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

--
Message posted from http://www.ExcelForum.com


acw[_2_]

Finding substrings within a string
 
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


--
Message posted from http://www.ExcelForum.com



Robin Hammond[_2_]

Finding substrings within a string
 
If Instr(str2, str1)0 then msgbox "found"

Robin Hammond
www.enhanceddatasystems.com

"Gaston " wrote in message
...
Sorry if this question seems trivial, but for the life of me, I can't
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.


---
Message posted from http://www.ExcelForum.com/




[email protected]

Finding substrings within a string
 
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
-----Original Message-----
Sorry if this question seems trivial, but for the life

of me, I can't
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.


---
Message posted from http://www.ExcelForum.com/

.



All times are GMT +1. The time now is 09:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com