The standard library’s str module and String type provide many useful string-related functions. Here are some examples to give you a sense of the available operations.
When you run this program, you’ll see:
In Rust, string manipulation is often done through methods on String or &str types, rather than functions in a separate module. However, the str module does provide some additional string-related utilities.
Some key differences to note:
Rust uses String for owned strings and &str for string slices.
Many operations in Rust are methods rather than standalone functions.
Rust’s split returns an iterator, which we collect into a Vec for printing.
Rust’s find returns an Option<usize>, which we handle with unwrap_or.
Rust doesn’t have a direct equivalent to Go’s strings.Count, so we use matches().count().
You can find more string-related functions and methods in the Rust documentation for the str module and String type.