Split string into parts

let st = String::from("/path/to/dir");
How to split that^^^ so I end up with parts:
0:/
1:path/
2:to/
3:dir

If you work with the standard library’s Path type instead, you can iterate over its components in a platform-independent manner. (The iter method is similar, but its items don’t give as much pre-“parsed” information as the Component enum does.)

4 Likes

Path::new("…").components() is the correct way, but for other string-splitting there's split_inclusive().

2 Likes