Splitting on an asterisk using a regular expression

Posted on 2006-05-09
Last Modified: 2010-05-18
Is there a way to split a string by an asterisk using a regular expression in C#?
Question by:jeshbr
    LVL 11

    Accepted Solution

    To use an asterisk in a regular expression, escape it with a backslash (the backslash, of course, needs to be escaped in c#, resulting in the code "\\*" or @"\*"):

      string input = "A*B*C";
      string[] output = System.Text.RegularExpressions.Regex.Split(input, "\\*");
      //output = string[] { "A", "B", "C" }

    You can also use the String.Split method in this case:

      output = input.Split('*');
    LVL 3

    Author Comment

    for some reason the Regex.Split does not work.

    but the string.Split works fine.
    LVL 3

    Author Comment


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now