You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't understand the solution to exercise 5 about slices:
fn main() {
let s = "你好,世界";
// Modify this line to make the code work
let slice = &s[0..2];
assert!(slice == "你");
println!("Success!");
}
The solution is:
fn main() {
let s = "你好,世界";
let slice = &s[0..3];
assert!(slice == "你");
}
Earlier, a comment to exercise 2 said that
Each of the two chars '中' and '国' occupies 4 bytes, 2 * 4 = 8
so I assumed 你 would occupy 4 bytes, and the slice would be &s[0..4]. Yet the correct answer is &s[0..3]. Apparently, in the fifth exercise, each Chinese character takes 3 bytes. Why so?
The text was updated successfully, but these errors were encountered:
I don't understand the solution to exercise 5 about slices:
The solution is:
Earlier, a comment to exercise 2 said that
so I assumed
你
would occupy 4 bytes, and the slice would be&s[0..4]
. Yet the correct answer is&s[0..3]
. Apparently, in the fifth exercise, each Chinese character takes 3 bytes. Why so?The text was updated successfully, but these errors were encountered: