I wasn't able to find the Rust equivalent for the "join" operator over a vector of String
s. I have a Vec<String>
and I'd like to join them as a single String
:
let string_list = vec!["Foo".to_string(),"Bar".to_string()];
let joined = something::join(string_list,"-");
assert_eq!("Foo-Bar", joined);
In Rust 1.3.0 and later,
SliceConcatExt::join
is available:Before 1.3.0 you can use
SliceConcatExt::connect
:Note that you do not need any imports as the methods are automatically imported by the standard library prelude.
There is a function from the
itertools
crate also calledjoin
which joins an iterator:As mentioned by Wilfred,
SliceConcatExt::connect
has been deprecated since version 1.3.0 in favour ofSliceConcatExt::join
: