Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在从文件中读取行,这些行如下所示:
89f81a03eb30a03c8708dde38cf:000391716
问题是:我想删除:(包括:)之后的所有内容。我尝试了所有我能在网上找到的东西,但它们似乎都在使用const char,而且这些线条是char指针。
:
const char
char
您可以使用strchr:
strchr
char str[] = "89f81a03eb30a03c8708dde38cf:000391716"; char *ptr; ptr = strchr(str, ':'); if (ptr != NULL) { *ptr = '\0'; }