/// Escape some special characters by placing a '\' in front
Escape some special characters by placing a '\' in front
Escape some special characters by placing a ' \ ' in front
pub fn escape_special_chars(s: &str) -> String {
    // Escape '\' first, otherwise it will be escaped later after it's added to escape something else
    const SPECIAL_CHARS: [char; 10] = ['\\', '&', '%', '$', '#', '_', '{', '}', '~', '^'];
    let mut s = s.to_owned();
    SPECIAL_CHARS.iter().for_each(|x| {
        s = s.replace(&format!("{}", x), &format!("\\{}", x));
    });
    s
}
pub fn escape_special_chars ( s : & str ) -> String { // Escape '\' first, otherwise it will be escaped later after it's added to escape something else const SPECIAL_CHARS : [ char ; 10 ] = [ '\\' , '&' , '%' , '$' , '#' , '_' , '{' , '}' , '~' , '^' ] ; let mut s = s . to_owned ( ) ; SPECIAL_CHARS . iter ( ) . for_each ( | x | { s = s . replace ( & format ! ( " " x ) , & format ! ( " \\ " x ) ) ; } ) ; s }
Escape some special characters by placing a '\' in front
Escape some special characters by placing a ' \ ' in front
s
&str