Rust
Rust
URL Encoding and Decoding
See more Encryption Examples
Demonstrates URL encoding and decoding.Chilkat Rust Downloads
// To URL encoding a string:
let s = "Why a > b?".to_string();
let sb = chilkat::StringBuilder::new();
let _ = sb.append(&s).is_ok();
// URL encode the string.
let _ = sb.encode("url", "utf-8");
// Show the URL encoded string:
let s_encoded = sb.get_as_string().unwrap_or_default();
println!("{}", s_encoded);
// The result is: Why%20a%20%3E%20b%3F
// If you prefer "+" instead of "%20" for SPACE chars:
let num_replaced = sb.replace("%20", "+");
println!("{}", sb.get_as_string().unwrap_or_default());
// Output is: Why+a+%3E+b%3F
// To decode:
let _ = sb.decode("url", "utf-8");
println!("{}", sb.get_as_string().unwrap_or_default());
// Result is: Why a > b?