Generation

generate functionSun, 13 Nov 2022

string replace function

fn find_replace(mut s: &str, from: &str, to: &str) -> String { let mut result = String::new(); let mut pos = 0; loop { if pos >= s.len() { break; } if &s[pos..pos+from.len()] == from { result.push_str(to); pos += from.len(); } else { result.push(s.chars().nth(pos).unwrap()); pos += 1; } } result }

Questions about programming?Chat with your personal AI assistant