How do I concatenate strings?

When you concatenate strings, you need to allocate memory to store the result. The easiest to start with is String and &str: fn main() { let mut owned_string: String = “hello “.to_owned(); let borrowed_string: &str = “world”; owned_string.push_str(borrowed_string); println!(“{}”, owned_string); } Here, we have an owned string that we can mutate. This is efficient as … Read more

Check if a string contains another string

Use the Instr function (old version of MSDN doc found here) Dim pos As Integer pos = InStr(“find the comma, in the string”, “,”) will return 15 in pos If not found it will return 0 If you need to find the comma with an excel formula you can use the =FIND(“,”;A1) function. Notice that … Read more

How to match a String against string literals?

UPDATE: Use .as_str() like this to convert the String to an &str: match stringthing.as_str() { “a” => println!(“0”), “b” => println!(“1”), “c” => println!(“2”), _ => println!(“something else!”), } Reason .as_str() is more concise and enforces stricter type checking. The trait as_ref is implemented for multiple types and its behaviour could be changed for type … Read more

Removing html tags from a string in R

This can be achieved simply through regular expressions and the grep family: cleanFun <- function(htmlString) { return(gsub(“<.*?>”, “”, htmlString)) } This will also work with multiple html tags in the same string! This finds any instances of the pattern <.*?> in the htmlString and replaces it with the empty string “”. The ? in .*? … Read more