rust defanged IP address
// A defanged IP address replaces every period "." with "[.]".
fn main() {
let ipaddr = "1.1.1.1".to_string();
defang_i_paddr(ipaddr); // resultstr is 1[.]1[.]1[.]1
}
fn defang_i_paddr(address: String) -> String {
let mut resultstr = "".to_string();
for (i,addr) in address.split(".").enumerate() {
// println!("addr is {} ",addr);
resultstr.push_str(addr);
if i != 3 {
resultstr.push_str("[.]");
}
}
println!("resultstr is {} ",resultstr);
return resultstr
}