这是我的test file
这是我的完整代码(github.com/roroco/ro_article/tree/string-contains-null-byte)
运行以下代码时出现“ArgumentError:字符串包含空字节”:
在 ruby 方面:
get_article(File.read("test_file"))
在c端:
VALUE get_article(VALUE self, VALUE html) {
str html2 = StringValueCStr(html);
test file这么大,如何找到这个文件中的空字节?以及如何使 StringValueCStr 适用于所有字符串,即使它包含“空字节”
最佳答案
当我使用以下代码时:
body = File.read("test_file")
result = body.inspect
我的“结果”包含“\u0000”(我的编码是utf8),所以解决方案是
body.gsub(%r{\u0000}, "")
在 ruby 端或 c 端执行
关于c - 参数错误: string contains null byte when use StringValueCStr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34916024/