-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
50 lines (42 loc) · 1.2 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* NOTE:
* push_str -> Add string
* push -> Add character
*/
fn translate_string(curr_str: &mut String) -> String
{
// Create blank string
let mut new_str = String::new();
// Iterate string
for letter in curr_str.chars()
{
// Use match operator to check how to modify string
match letter
{
'a' | 'e' | 'i' | 'o' | 'u' => {
// Add current string to new string and append "-hay" to it
new_str.push_str(curr_str);
new_str.push_str("-hay");
},
_ => {
// Add current string to new string and remove the 1st letter
new_str.push_str(curr_str);
new_str.remove(0);
// Append -{letter}ay
new_str.push('-');
new_str.push(letter);
new_str.push_str("ay");
},
}
// Exit for-loop
break;
}
// Return new string
new_str
}
fn main() {
// Test strings
let mut str_1 = String::from("apple");
let mut str_2 = String::from("first");
println!("{}", translate_string(&mut str_1));
println!("{}", translate_string(&mut str_2));
}