1. 位置:在kernel/lib/string.c中,头文件
2. 函数功能:破坏性分割字符串,返回分割前一部分,后一部分保存在原字符中
3. 函数原型:char * strsep(char ,const char *);
/ * strsep - Split a string into tokens * @s: The string to be searched * @ct: The characters to search for * * strsep() updates @s to point after the token, ready for the next call. * * It returns empty tokens, too, behaving exactly like the libc function * of that name. In fact, it was stolen from glibc2 and de-fancy-fied. * Same semantics, slimmer shape. ;) */ char *strsep(char s, const char *ct) { char *sbegin = *s; char *end; if (sbegin == NULL) return NULL; end = strpbrk(sbegin, ct); if (end) *end++ = '\0'; *s = end; return sbegin; } EXPORT_SYMBOL(strsep);
4. 函数用法:
int main() { char s[] = "abcdefg_hijklmn_opqrst"; char *t, *de = "_"; while (s && s != '\0') { t = strsep(&s, de); printk("%s\n", t); } }
6. 到这里可以看到strsep返回的是分割后的第一部分字符串,保存在t里面, s保存分割后剩下的部分
PS: 当s里面没有分隔符时,t保存的是整个字符串,s保存的是’\0′
以上,如有不对,欢迎指正!
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/222079.html原文链接:https://javaforall.net
