C
C#9mo ago
Pokey

❔ ✅ Parsing path into parts with varying separators?

The traditional way to do this would be
string myPath = "C:\\Users\\Me\\Desktop";
string[] myPathParts = myPath.Split(Path.DirectorySeparatorChar);
string myPath = "C:\\Users\\Me\\Desktop";
string[] myPathParts = myPath.Split(Path.DirectorySeparatorChar);
But what if the path uses / instead of \ because as far as I am aware Windows will understand this, but that wouldn't be the DirectorySeparatorChar? Thanks!
7 Replies
cap5lut
cap5lut9mo ago
String.Split Method (System)
Returns a string array that contains the substrings in this instance that are delimited by elements of a specified string or Unicode character array.
MODiX
MODiX9mo ago
cap5lut
REPL Result: Success
"a:\\b/c".Split('\\', '/')
"a:\\b/c".Split('\\', '/')
Result: string[]
[
"a:",
"b",
"c"
]
[
"a:",
"b",
"c"
]
Compile: 522.920ms | Execution: 32.986ms | React with ❌ to remove this embed.
Pokey
Pokey9mo ago
Aha... I feel stupid now haha Thank you
cap5lut
cap5lut9mo ago
glad i could help, if ur question is answered please mark the thread as such by $closing it
MODiX
MODiX9mo ago
Use the /close command to mark a forum thread as answered
Pokey
Pokey9mo ago
Aha I was trying to find how you're meant to do that, thanks again 😛
Accord
Accord9mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.