How to split string on backslash or forward slash in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string s = @"C:/Users/Name/Documents\C#\Examples\Strings\Split";

        string[] arr = s.Split(new char[] { '/', '\\' });

        foreach (string element in arr)
            Console.WriteLine(element);
    }
}




/*
run:

C:
Users
Name
Documents
C#
Examples
Strings
Split

*/

 



answered Oct 26, 2022 by avibootz

Related questions

1 answer 178 views
1 answer 126 views
126 views asked Oct 26, 2022 by avibootz
1 answer 135 views
1 answer 128 views
128 views asked Oct 26, 2022 by avibootz
1 answer 149 views
149 views asked Oct 26, 2022 by avibootz
1 answer 245 views
1 answer 207 views
...