在Common Lisp中,可以使用flexi-streams
库来将字节数组转换为字符串。以下是一个简单的示例:
flexi-streams
库。如果没有,请使用以下命令安装:(ql:quickload "flexi-streams")
(defun byte-array-to-string (byte-array)
(let ((flexi-stream (make-instance 'flexi-streams:flexi-stream
:external-format '(:utf-8 :eol-style :lf)
:element-type '(unsigned-byte 8))))
(setf (flexi-streams:flexi-stream-stream flexi-stream)
(make-instance 'flexi-streams:in-memory-stream
:content byte-array))
(flexi-streams:get-output-stream-string flexi-stream)))
(defparameter *byte-array* (vector 72 101 108 108 111 32 87 111 114 108 100))
(byte-array-to-string *byte-array*)
输出结果:
"Hello World"
这样,您就可以在Common Lisp中将字节数组转换为字符串。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云