-
Code fn split(string: &str, separator: char) -> Vec<&str> { string.split(separator).collect() }
Test Cases fn test() { assert_eq!(split("Hello World", ' '), ["Hello", "World"]); assert_eq!(split("John-brings-his-cat", '-'), ["John", "brings", "his", "cat"]); }
Output:
-
Code #include <string>#include <sstream>#include <vector>auto split(const std::string& str, char sep) {auto result = std::vector<std::string>{};auto stream = std::stringstream(str);auto buffer = std::string{};while (std::getline(stream, buffer, sep)) result.emplace_back(buffer);return result;- fn split(string: &str, separator: char) -> Vec<&str> {
- string.split(separator).collect()
- }
Test Cases // TODO: Replace examples and use TDD by writing your own testsDescribe(any_group_name_you_want){It(should_do_something){Assert::That(split("Hello World", ' '), Equals(std::vector<std::string>{"Hello", "World"}));Assert::That(split("John-brings-his-cat", '-'), Equals(std::vector<std::string>{"John","brings","his","cat"}));}};- #[test]
- fn test() {
- assert_eq!(split("Hello World", ' '), ["Hello", "World"]);
- assert_eq!(split("John-brings-his-cat", '-'), ["John", "brings", "his", "cat"]);
- }
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}