string.Split()

I have an array with seperators:

string[] operators = { " LIKE ", " NOT LIKE ", " < ", " > ", " <= ", " >= ", " in ", " not in ", " is null ", " is not null " };

I want to split a string (a query) but after the split I want to know which seperator of the array was used.

Can someone help me with this

thanks!



Answer this question

string.Split()

  • Alexander Medvedev

    I think you have to the separation without the split method, i have never heard that there was a way to tell what separator was used. Every separated string could have been separated with different separator, so the string itself should contain info about the separator (and it don't).


    You could define method that returns an array of structures that contain the string/separator pairs. Put the method to some appropriate class.

    here's some examples to help you to understand what im trying to say:
    public struct SplittedString
    {
        public string value;
        public string separator;
    }

    public SplittedString[] Split(string text, param string[] separators)
    {
        List<SplittedString> splittedStrings = new List<SplittedString>();

        //do your separation logic here
        //1. split the "text" string
        //2-n. using String.IndexOf, String.Contains etc., define in which order separators was used

        return splittedStrings.ToAttay();
    }

  • mta37

    I wrote an example how it can be done in another thread.

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=121973&SiteID=1



  • hugo s

    thanks! that is what i was looking for!

  • string.Split()