Byte literal not escaped when pushed onto String


#1

Problem

The escaping backslash in the byte literal for apostrophe b’\’’ is not removed when used in a String.

Example

O’Brien becomes O\'Brien


Here are some code snippets to show it…

let apos = vec![39];
print!("{:?}",String::from_utf8(apos).unwrap());

prints out “\’”

let apos: char = '\'';
let mut s = String::new();
s.push(apos);
print!("{:?}",s);	

prints out “\’”

let apos: char = '\'';
print!("byte literal is {:?} and u8 is {:?}",b'\'', apos as u8);

prints out byte literal is 39 and u8 is 39


Question

How can remove the escaping backslash when pushing the char onto a String, so that O’Brien remains O’Brien?


#2

Try using the Display output (ie {}) format instead of Debug (ie {:?})


#3

thank you very much. You are correct. I was using Debug in my tests so they kept failing. Display works.