I cant find an expression to evaluate a part of a string.
I want to get something like that:
if (string[4:8]=='abc') {...}
I started writing like this:
if (string[4]=='a' && string[5]=='b' && string[6]=='c') {...}
but if i need to evaluate a big part of string like
if (string[10:40] == another_string) {...}
then it gets to write TOO much expressions. Are there any ready-to-use solutions?
You could always use strncmp()
, so string[4:8] == "abc"
(which isn't C syntax, of course) could become strncmp(string + 4, "abc", 5) == 0
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With