Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a string where separator is mixed with regular characters?

Tags:

c#

I would like to split string "203136;70;;;;;" by ;; separator but in this string separator was mixed with regular symbol ;

From "203136;70;;;;;"

To

  • 203136;70
  • ;
like image 401
Snail Avatar asked Nov 27 '25 20:11

Snail


1 Answers

You can use StringSplitOptions.RemoveEmptyEntries:

using System;

class Program
{
    static void Main()
    {
        string input = "203136;70;;;;;";
        string[] result = input.Split(new string[] { ";;" }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string r in result)
        {
            Console.WriteLine(r);
        }
    }
}
203136;70
;
like image 154
NoName Avatar answered Nov 30 '25 11:11

NoName



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!