Split string by a substring

前端 未结 4 615
清酒与你
清酒与你 2021-01-19 16:48

I have following string:

char str[] = \"A/USING=B)\";

I want to split to get separate A and B values with /

4条回答
  •  心在旅途
    2021-01-19 17:05

    I known strtok() but it just split by one character as delimiter

    Nopes, it's not.

    As per the man page for strtok(), (emphasis mine)

    char *strtok(char *str, const char *delim);

    [...] The delim argument specifies a set of bytes that delimit the tokens in the parsed string. [...] A sequence of two or more contiguous delimiter bytes in the parsed string is considered to be a single delimiter. [...]

    So, it need not be "one character" as you've mentioned. You can using a string, like in your case "/USING=" as the delimiter to get the job done.

提交回复
热议问题