to_bytes
fn to_bytes(string s) -> Vec<byte> Import
Source: use string::{to_bytes}; compiler/src/builtin_docs/string.hy Encodes s as UTF-8 into a new Vec<byte>.
Always succeeds; the result has s.len() bytes. Use it to pass text to
io::write and the other byte-based IO functions.
Parameters#
| Name | Type |
|---|---|
s | string |
Returns#
Vec<byte>
Examples#
use string::{to_bytes};
use tests::assert;
let b = to_bytes("Hi");
assert!(b.len() == 2);
assert!(b[0] == 72 as byte && b[1] == 105 as byte);
See also#
Vecio::writebyte_at: Returns the byte at byte offsetiofs, or-1wheniis out of range.find_from: Returns the byte offset of the firstneedleinhayat or afterstart, or-1.format: Builds a string from the literalfmtand the arguments that follow it.from_bytes: Decodesbytesas UTF-8 text.match_at: Returns whetherneedleoccurs insstarting exactly at byte offsetat.rfind: Returns the byte offset of the lastneedleinhay, or-1.