String Searching - Substring VS indexOf()

Hello,

I'm working on a remote home monitoring system for my off grid cabin. I have the MKR GSM that I will text to get status updates. In the code I'm writing I'm searching the incoming phone number to only respond to my phone, and then searching the text body for commands.

As I research code I see a lot of string searching uses indexOf(). Not many examples use Substring. Is there a reason? Is there an advantage to one over the other? Maybe it's splitting hairs and it doesn't matter for a non-intensive application.

Thanks for your input, Spanky

subString() does not search; it returns the part of a String that wa specified. indexOf() searches.

By the way, your better off not using String (capital S). It will sooner or later byte you with difficult to understand runtime failures.

Thanks for the information!

sterretje: By the way, your better off not using String (capital S). It will sooner or later byte you with difficult to understand runtime failures.

Instead of String, do I use a char array? If that's the case can I do indexOf on a char array? Thanks

No, you can't use indexOf, but strstr provides a similar function.

Find yourself a good C string tutorial.