1

I have following string which is a comma separated list

Dim str1, str2

str1="C_adminToolsChartsOnFormsManager,C_adminToolsFormDesignerCopyFormDesign,C_adminToolsManageLocationsAccessSubSystem,C_adminToolsManageLocationsAddLocation,C_adminToolsManageLocationsCopyLocation"
str2="C_adminToolsFormDesigner"

I want to search str2 in str1 with exact match. C_adminToolsFormDesigner should not match with C_adminToolsFormDesignerCopyFormDesign.

I have used below single expression but it always returns true. It should do the exact match and should return false.

IIF(InStr(str1,str2),"True","False")

Can anyone help me in writing the single line expression?

trincot
  • 317,000
  • 35
  • 244
  • 286

1 Answers1

1

You could check for the commas, like so:

result = IIf(InStr("," & str1 & ",", "," & str2 & ","), "True", "False")

NB: I'm not sure why you would want True and False as String data type. It seems more natural to produce a Boolean value:

result = InStr("," & str1 & ",", "," & str2 & ",") > 0
trincot
  • 317,000
  • 35
  • 244
  • 286
  • Glad to hear it was useful! If you wish to do so, you can also [mark the answer as accepted](http://stackoverflow.com/help/someone-answers), but it is optional. – trincot Jun 07 '23 at 17:01