gpt4 book ai didi

c - 从字符串中提取字符串值

转载 作者:行者123 更新时间:2023-12-04 10:30:16 24 4
gpt4 key购买 nike

海湾合作委员会 4.4.3c89

我有以下字符串

sip:12387654345443222118765@xxx.xxx.xxx.xxx

我怎样才能只提取数字?我只想要号码。

12387654345443222118765

非常感谢任何建议,

最佳答案

有很多方法可以做到这一点,如果字符串格式正确,您可以使用 strchr() 搜索 : 并使用 strchr () 再次搜索 @ 并获取其间的所有内容。

这是另一种查找连续数字序列的方法:

char *start = sipStr + strcspn(sipStr, "0123456789");
int len = strspn(start, "0123456789");

char *copy = malloc(len + 1);

memcpy(copy, start, len);
copy[len] = '\0'; //add null terminator

...
//don't forget to
free(copy);

关于c - 从字符串中提取字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3074755/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com