MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / capitalize_title

Function capitalize_title

2129-capitalize-the-title.rs:2–14  ·  view source on GitHub ↗

to_lowercase() 和 to_ascii_uppercase()的区别,一个是针对字符串,一个是针对字符。

(title: String)

Source from the content-addressed store, hash-verified

1// to_lowercase() 和 to_ascii_uppercase()的区别,一个是针对字符串,一个是针对字符。
2pub fn capitalize_title(title: String) -> String {
3 let mut ret_arr: Vec<String> = vec![];
4 for word in title.split_ascii_whitespace() {
5 if word.len() < 3 {
6 ret_arr.push(word.to_lowercase());
7 } else {
8 let mut tmp: Vec<char> = word.to_lowercase().chars().collect();
9 tmp[0] = tmp[0].to_ascii_uppercase();
10 ret_arr.push(tmp.iter().collect::<String>());
11 }
12 }
13 ret_arr.join(" ")
14}
15
16fn main() {
17 let title = "capiTalIze OF titLe".to_string();

Callers

nothing calls this directly

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected