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 244 views
1 answer 197 views
197 views asked Oct 26, 2022 by avibootz
1 answer 195 views
1 answer 204 views
204 views asked Oct 26, 2022 by avibootz
1 answer 223 views
223 views asked Oct 26, 2022 by avibootz
1 answer 340 views
1 answer 300 views
...