byte_at
fn byte_at(string s, int i) -> int Import
Source: use string::{byte_at}; compiler/src/builtin_docs/string.hy Returns the byte at byte offset i of s, or -1 when i is out of range.
Offsets count UTF-8 bytes, not characters, and s.len() is the byte
length. The result is 0..=255 for any offset in 0..s.len().
Parameters#
| Name | Type |
|---|---|
s | string |
i | int |
Returns#
int
Examples#
use string::{byte_at};
use tests::assert;
assert!(byte_at("abc", 0) == 97);
assert!(byte_at("abc", 3) == -1);
assert!(byte_at("abc", -1) == -1);
See also#
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.slice_bytes: Returns the part ofsbetween byte offsetsstart(inclusive) andend(exclusive).to_bytes: Encodessas UTF-8 into a newVec<byte>.