matching strings

k_babb

Board Regular
Joined
Mar 28, 2011
Messages
71
how can i check if a2 string is a sub string of b2

so if a2 is "Apple And pears"

and b2 is " bananna Apple And pears" this is a match

but if b2 is "Apple" should be false as it does not contain the full string of a2
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
This is case insenesitive, if you want case sensitive use FIND

=IF(ISNUMBER(SEARCH(A1, B1)), "its there", "not")
 
Upvote 0
how can i check if a2 string is a sub string of b2

so if a2 is "Apple And pears"

and b2 is " bananna Apple And pears" this is a match

but if b2 is "Apple" should be false as it does not contain the full string of a2
If you don't want the match to be case sensitive change FIND to SEARCH in the formula.
Excel Workbook
ABC
2Apple And pearsbanana Apple And pearsTRUE
Sheet3
 
Upvote 0
This is case insenesitive, if you want case sensitive use FIND

=IF(ISNUMBER(SEARCH(A1, B1)), "its there", "not")

Another way to do the case insensitive test is like this (one less function call)...

=IF(COUNTIF(B1,"*"&A1&"*"),"its there","not")
 
Upvote 0
Another way to do the case insensitive test is like this (one less function call)...

=IF(COUNTIF(B1,"*"&A1&"*"),"its there","not")
Is a function (with letters) slower than those functions of two arguments called "operations".

ISNUMBER(SEARCH(A1, B1)) - 2 calls: ISNUMBER and SEARCH

COUNTIF(B1,"*"&A1&"*") - 3 calls: COUNTIF, & and &

(My math backround sees the difference between SUM(1,2) and 1+2 as the first uses pre-script notation and the other uses mid-script notation. )
 
Last edited:
Upvote 0
Is a function (with letters) slower than those functions of two arguments called "operations".

ISNUMBER(SEARCH(A1, B1)) - 2 calls: ISNUMBER and SEARCH

COUNTIF(B1,"*"&A1&"*") - 3 calls: COUNTIF, & and &

(My math backround sees the difference between SUM(1,2) and 1+2 as the first uses pre-script notation and the other uses mid-script notation. )
I see concatenation which is a pure memory/copy type activity as being different than a function call (which has to marshal the function, pass arguments, execute code that is who knows how long or involved and then finally pass back a result). Now, of course, some functions are quite fast (LEN for example) and others are quite slow (most array functions I would guess), so that could affect comparisons for competing formulas, but I really don't know how efficient each individual function actually is. My general rule for estimating formula efficiency has been the quite course measure I used here... the less function calls, the more efficient... I am sure there are many exceptions, but as a general rule, I believe that tends to work. I know there are some out there who have some "tools" which can actually measure the speed of a formula... I don't have such a tool, but that would be the way to go if fine time difference measurements between competing formulas was seriously needed.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top