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 163 views
1 answer 107 views
107 views asked Oct 26, 2022 by avibootz
1 answer 118 views
1 answer 117 views
117 views asked Oct 26, 2022 by avibootz
1 answer 133 views
133 views asked Oct 26, 2022 by avibootz
1 answer 190 views
1 answer 227 views
...