从字符串中提取未知子字符串
我有一个程序以以下格式返回数据:
<CFData 0x1001219c0 [0x7fff7027aee0]>{length = 20, capacity = 20, bytes = 0x8deead13b8ae7057f6a629fdaae5e1200bcb8cf5}
我需要提取 8deead13b8ae7057f6a629fdaae5e1200bcb8cf5
(是的,减去 0x
)。我尝试使用 sscanf 并传递一些正则表达式,但我对此一无所知。
知道如何做到这一点吗?代码片段值得赞赏。
I have a program returning data in the following format:
<CFData 0x1001219c0 [0x7fff7027aee0]>{length = 20, capacity = 20, bytes = 0x8deead13b8ae7057f6a629fdaae5e1200bcb8cf5}
I need to extract 8deead13b8ae7057f6a629fdaae5e1200bcb8cf5
(yes, minus the 0x
). I tried using sscanf
and passing some regular expressions but I have no clue on that.
Any idea how to do this? Code snippets are appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 strstr() 在输入中找到“bytes = 0x” string 并复制字符串的其余部分(从“bytes = 0x”末尾开始),最后一个字符除外:
You could use strstr() to locate "bytes = 0x" in the input string and copy the remainder of the string (from the end of "bytes = 0x") except for the last character:
您可以使用
strtok
来实现这一目的。请注意,这只是一个示例。您应该强烈考虑使用
strtok_r
重写它,因为strtok
是不可重入的。You can use
strtok
to do the trick.Note that this is only a sample. You should strongly consider rewriting this using
strtok_r
, becausestrtok
is not re-entrant.