trim
fn trim(string s) -> Result<string, string> Import
Source: use text::{trim}; src/text.hy Returns s without leading and trailing ASCII whitespace (space, tab, CR, LF).
Other Unicode whitespace is kept. The Result never holds an error for valid
input; it exists because trimming works on bytes.
Parameters#
| Name | Type |
|---|---|
s | string |
Returns#
Result<string, string>
Contracts#
Checked according to --contracts (see Contracts).
ensures ok_len(result) >= 0 && ok_len(result) <= s.len()
Examples#
use text::{trim};
use tests::assert;
assert!((trim("\t key = value \r\n") ?? "") == "key = value");
See also#
Resultbyte_len: Returns the length ofsin bytes; the same ass.len().slice: Returns the part ofsfrom byte offsetstartup to (not including)end.trim_start: Returnsswithout leading ASCII whitespace (space, tab, CR, LF).trim_end: Returnsswithout trailing ASCII whitespace (space, tab, CR, LF).rfind: Returns the byte offset of the lastneedleinhay, or-1.split_at: Splitssat byte offsetatinto the part before and the part fromaton.join: Returns thepartsconcatenated withsepbetween each pair.