开发者

"hello x" - string compare

开发者 https://www.devze.com 2023-03-26 22:42 出处:网络
I need to see if my string matches \"hello X\" where X is any i开发者_开发问答nt. Basically I want to catch if its \"hello 1\" or \"hello 100\".

I need to see if my string matches "hello X" where X is any i开发者_开发问答nt.

Basically I want to catch if its "hello 1" or "hello 100".

How best can I do it?

Edit 0

Thanks Andrea Bergia.

I am using your code like this:

int dummy;
if (sscanf(string, "hello %d", &dummy))
    /* matched */


int dummy;
int n = sscanf(string, "hello %d", &dummy);
if (n == 1) {
    // Matched
}


Several ways to go about it. First thought is to use a regular expression, but that may be over kill for your requirements.

http://www.gnu.org/s/hello/manual/libc/Pattern-Matching.html

0

精彩评论

暂无评论...
验证码 换一张
取 消