本文簡要介紹rust語言中 std::string::String.split_off 的用法。
用法
pub fn split_off(&mut self, at: usize) -> String在給定的字節索引處將字符串拆分為兩個。
返回一個新分配的 String 。 self 包含字節 [0, at) ,返回的 String 包含字節 [at, len) 。 at 必須位於 UTF-8 代碼點的邊界上。
請注意,self 的容量不會改變。
Panics
如果 at 不在 UTF-8 代碼點邊界上,或者如果它超出字符串的最後一個代碼點,則會出現Panics。
例子
let mut hello = String::from("Hello, World!");
let world = hello.split_off(7);
assert_eq!(hello, "Hello, ");
assert_eq!(world, "World!");相關用法
- Rust String.shrink_to_fit用法及代碼示例
- Rust String.shrink_to用法及代碼示例
- Rust String.try_reserve用法及代碼示例
- Rust String.insert_str用法及代碼示例
- Rust String.into_raw_parts用法及代碼示例
- Rust String.extend_from_within用法及代碼示例
- Rust String.clear用法及代碼示例
- Rust String.reserve用法及代碼示例
- Rust String.from_utf16_lossy用法及代碼示例
- Rust String.push用法及代碼示例
- Rust String.as_bytes用法及代碼示例
- Rust String.as_str用法及代碼示例
- Rust String.with_capacity用法及代碼示例
- Rust String.remove用法及代碼示例
- Rust String.from_utf8_lossy用法及代碼示例
- Rust String.into_bytes用法及代碼示例
- Rust String.replace_range用法及代碼示例
- Rust String.from_utf16用法及代碼示例
- Rust String.from_utf8_unchecked用法及代碼示例
- Rust String.into_boxed_str用法及代碼示例
- Rust String.new用法及代碼示例
- Rust String.insert用法及代碼示例
- Rust String.capacity用法及代碼示例
- Rust String.try_reserve_exact用法及代碼示例
- Rust String.as_mut_str用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 std::string::String.split_off。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
