How to accept &str, String and &String in a single function?

You can use the AsRef<str> trait: // will accept any object that implements AsRef<str> fn print<S: AsRef<str>>(stringlike: S) { // call as_ref() to get a &str let str_ref = stringlike.as_ref(); println!(“got: {:?}”, str_ref) } fn main() { let a: &str = “str”; let b: String = String::from(“String”); let c: &String = &b; print(a); print(c); print(b); … Read more

How to write a multiline string in Swift?

Swift 4 includes support for multi-line string literals. In addition to newlines they can also contain unescaped quotes. var text = “”” This is some text over multiple lines “”” Older versions of Swift don’t allow you to have a single literal over multiple lines but you can add literals together over multiple lines: var … Read more

Removing spaces from a variable input using PowerShell 4.0

The Replace operator means Replace something with something else; do not be confused with removal functionality. Also you should send the result processed by the operator to a variable or to another operator. Neither .Replace(), nor -replace modifies the original variable. To remove all spaces, use ‘Replace any space symbol with empty string‘ $string = … Read more