Optimized algorithm to search string from given string array or long text string