需求:提供字符串“/data/xxx_yyyy_123_567.zip”,想要获取".zip"之前的内容/data/xxx_yyyy_123_567
函数实现如下
int getSplitString(char *path, char *name)
{
char delim[] = ".";
char *token;
char *s = path;
token = strsep(&s, ".");
strcpy(name, token);
return 0;
}
char fp[128] = "/data/xxx_yyyy_123_567.zip";
char tmp[100] = {0};
int ret;
ret = getSplitString(fp, tmp);
printf("tmp is:%s\n", tmp);
运行结果:
tmp is:/data/xxx_yyyy_123_567