코딩Coding/Rust연습

rust연습]u8_sting_stack저장하기bytes() / std::str

내인생PLUS 2022. 4. 18. 01:44
728x90

 

use std::str;

fn main() {
    for b in "안녕 ".bytes() {
        println!("{}", b);
    }
    let a = vec![236, 149, 136, 235, 133, 149, 32];
    let a = str::from_utf8(&a).unwrap();
    println!("{a}");
}

 

결과

236
149
136
235
133
149
32
안녕 

 

 

 

https://doc.rust-lang.org/std/str/fn.from_utf8.html

 

from_utf8 in std::str - Rust

Converts a slice of bytes to a string slice. A string slice (&str) is made of bytes (u8), and a byte slice (&[u8]) is made of bytes, so this function converts between the two. Not all byte slices are valid string slices, however: &str requires that it is v

doc.rust-lang.org

 

 

 

 

 

 

 


 

반응형