Hello I would like to compare two string to each other.I would like that there is color in text.
String text="My color is black";
String color="black";
How can I do that?
Thanks.
Hello I would like to compare two string to each other.I would like that there is color in text.
String text="My color is black";
String color="black";
How can I do that?
Thanks.
Tried if(text.indexOf(color) > 0)?
Old-fashioned here
If you don't use String (capital S) but character arrays
char text[] = "My color is black";
char color[] = "black";
if(strstr(text, color) != NULL)
{
// match
}
else
{
// no match
}
JaBa:
Tried if(text.indexOf(color) > 0)?
That would not work if the text is "black is my favorite color", it would return 0 which you exclude with strictly greater. The function returns -1 if not found, that is what needs to be tested.
Obviously our recommendation would be to not use Strings with a capital S and go lower level with char arrays.