I have a csv file with a first column of data that represents an element code that optionally ends with "UNIUNI" or a mixed case of these characters downloaded using a barcode reader. I need to trim the last "UNI" s.
In Rust, I tried to write with partial success a function like this:
fn main() { // Ok: from "9846UNIUNI" to "9846" println!("{}", read_csv_rilev("9846UNIUNI".to_string())); // Wrong: from "9846uniuni" to "9846" println!("{}", read_csv_rilev("9846uniuni".to_string())); } fn read_csv_rilev(code: String) -> String { code //.to_uppercase() /*Unstable feature in Rust 1.1*/ .trim_right_matches("UNI") .to_string() }
The ideal function signature looks like this:
fn read_csv_rilev(mut s: &String) {}
but probably in-place action in String is not a good idea. In fact, there is nothing to be done in the Rust standard library except String::pop() .
Is there a way to apply cropping on a String without highlighting another?
source share