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 164 views
1 answer 109 views
109 views asked Oct 26, 2022 by avibootz
1 answer 120 views
1 answer 119 views
119 views asked Oct 26, 2022 by avibootz
1 answer 134 views
134 views asked Oct 26, 2022 by avibootz
1 answer 192 views
1 answer 230 views
...