Searching for string within a file

To search for a specific substring within any type of file, we can use this rather complex function.
As a parameter, just pass the filename, substring you want to search and finally set true or false, if you want to search case sensitive.