1

我有一个缓冲区

问题 1

我怎样才能一个一个地打印出里面的所有字节?

问题2

如何控制打印格式?

例如,如果我有一个像这样的缓冲区33 33 33 33 33 33 14 40(每个字节都是十六进制格式),我怎么能把它打印成\x33\x33\x33\x33\x33\x33\x14\x40

4

1 回答 1

2

To apply an imperative function f to every byte in a buffer b, you can use String.iter f (Buffer.contents b).

To print a value with a desired format, you can use Printf.printf.

To get the integer value of a byte in a string you can use Char.code.

As a side comment, many of your recent questions could be answered extremely quickly by reading through the OCaml standard library documentation. I think this would be a good thing for you to do. There's not a lot of deep intellectual content, it's just something you should know about as an OCaml programmer.

于 2013-04-26T15:07:48.290 回答