How to split a string with multi-character delimiter into an array of strings in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "c#,! java, @@c,c++,!!!python";
            char[] delimiter = { '\'','!', '@', '*', '$', ',' };
            string[] arr = s.Split(delimiter, StringSplitOptions.None);

            foreach (string part in arr)
            {
                Console.WriteLine(part);
            }
        }
    }
}

/*
run:

c#

 java


c
c++



python

*/

 



answered Jan 23, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "c#,! java, @@c,c++,!!!python";
            char[] delimiter = { '\'','!', '@', '*', '$', ',', ' ' };
            string[] arr = s.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);

            foreach (string part in arr)
            {
                Console.WriteLine(part);
            }
        }
    }
}

/*
run:

c#
java
c
c++
python

*/

 



answered Jan 23, 2017 by avibootz

Related questions

1 answer 177 views
2 answers 231 views
1 answer 167 views
1 answer 127 views
1 answer 137 views
1 answer 170 views
...