Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split path by "\\" in C#

Tags:

c#

split

How can I split a path by "\\"? It gives me a syntax error if I use

path.split("\\");
like image 275
kartal Avatar asked Nov 26 '22 21:11

kartal


2 Answers

You should be using

path.Split(Path.DirectorySeparatorChar);

if you're trying to split a file path based on the native path separator.

like image 109
Mat Avatar answered Dec 15 '22 17:12

Mat


Try path.Split('\\') --- so single quote (for character)

To use a string this works:

path.Split(new[] {"\\"}, StringSplitOptions.None)

To use a string you have to specify an array of strings. I never did get why :)

like image 43
Eben Roux Avatar answered Dec 15 '22 17:12

Eben Roux