Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C: evaluate part of the string

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?

like image 205
Vladimir Keleshev Avatar asked Feb 28 '23 06:02

Vladimir Keleshev


1 Answers

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.

like image 108
David Thornley Avatar answered Mar 07 '23 19:03

David Thornley