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 249 views
1 answer 203 views
203 views asked Oct 26, 2022 by avibootz
1 answer 199 views
1 answer 208 views
208 views asked Oct 26, 2022 by avibootz
1 answer 228 views
228 views asked Oct 26, 2022 by avibootz
1 answer 347 views
1 answer 306 views
...