Reputation: 3064
I have a variable named "String" that may have values like the following ones:
const char* String = "/v1/AUTH_abb52a71-fc76-489b-b56b-732b66bf50b1/test/DSC_0188.JPG";
or
const char* String = "/auth/v1.0";
or
const char* String = "/v2/AUTH_abb52a71-fc76-489b-b56b-732b66bf50b1/images?limit=1000&delimiter=/&format=xml";
Now I want to make sure whether or not "String" has the character 'v1'. Checking this has to be precise. I tried with strchr, but it's not quite accurate as it doesn't take 'v1' as one character, it rather takes 'v' and '1' as two separate characters. Moreover I can't use namepace std and library string, I can only use "string.h". Within these limitations how can I accurately check whether the variable "String" has a character 'v1'?
Thank you.
Upvotes: 0
Views: 115
Reputation: 46963
v1
is not character according to any alphabet. This is a proper string "v1" and as @cnicutar mentioned the c way to search for string in string is to use strstr
. It is quite easy to use and runs KMP which is also very fast (though for the kind of your string it is not that crucial).
I would advise you to:
String
-> my_string
)const char[]
, no need to interfere with pointers, when you can avoid them. Declaring this as pointer might confuse you, that you dynamically allocated the memory for the string.Upvotes: 3