简体   繁体   English

在C中的某个字符后从字符串中删除文本

[英]Remove text from string after a certain character in C

I am reading lines from a file, the lines look like this: 我正在从文件中读取行,这些行看起来像这样:

89f81a03eb30a03c8708dde38cf:000391716

The thing is: I want to remove everything after the : (including the : ). 问题是:我想以后删除一切: (包括: )。 I tried everything I could find online but they seem to use const char and the lines are char pointers. 我尝试了我可以在网上找到的所有内容,但它们似乎使用了const char而且这些行是char指针。

You can use strchr : 你可以使用strchr

char str[] = "89f81a03eb30a03c8708dde38cf:000391716";
char *ptr;

ptr = strchr(str, ':');
if (ptr != NULL) {
    *ptr = '\0';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM