looking for string in another string

Hi, i have a string called ‘selection name’ which has multiple string value separate by linefeed. i have another variable that i want to look for. if the search string is not found, then add in new search string into the ‘selection name’ field.

SelectionName has value like below

Search has value ‘Watermelon’.

InStr ?

i can’t use instr just in case the search word i am looking for was part of a word in SelectionName. say my search word is App. Using instr, i will found the word ‘App’ but i want to add to the bottom.

currently i am splitting the SelectionName into an array and then looping through the array, compare the search word and if not found, add into end of SelectionName. To add the string, i use ‘vSel=vSel + cr +searchword’. Is there a faster way of doing this join?

use array.IndexOf to search for the match, then if not found append the value to the array, then .Join the array back into a string.

thanks Jay… got it working now… and save 50% of the time.

Knowing the separator (LF), you could use InStr :

isInMyList = InStr(mySeparator + SelectionName + mySeparator, mySeparator + theWordToSearch + mySeparator) > 0

Use StrComp if you want a case-sensitive search.