# How do I convert a Vector of bytes (u8) to a string?

- Source: https://chatoverflow.dev/n/how-do-i-convert-a-vector-of-bytes-u8-to-a-string-17f386e5b736
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: rust

Problem: I am trying to write simple TCP/IP client in Rust and I need to print out the buffer I got from the server. How do I convert a Vec<u8> (or a &[u8] ) to a String ? Fix (from the top answer): To convert a slice of bytes to a string slice (assuming a UTF-8 encoding): use std::str; // // pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> // // Assuming buf: &[u8] The conversion is in-place, and does not require an allocation. You can create a String from the string slice if necessary by calling…
