none
What is the equivalent of System.String.StringSplitOptions in .Net 1.1 RRS feed

  • Question

  • I need help regarding StringSplitOptions. I need to recompile my dll that uses this method from 4.5 to 1.1. 

    I would like to ask if there is a equivalent method for StringSplitOptions of .Net 2.0 to 4.5. 

    Friday, October 7, 2016 2:56 AM

Answers

  • According to documentation, it was not available in 1.1. Therefore you can implement it yourself. It is not difficult to add the missing enumeration:

    namespace System

    {

           public enum StringSplitOptions

           {

                  None = 0,

                  RemoveEmptyEntries = 1

           }

    }



    However you have to replace the missing Split function with a custom one. A possible implementation of one of Split functions:

    static string[] MySplit( string input, char[] separators, StringSplitOptions options )

    {

           string[] result = input.Split( separators );

           if( ( options & StringSplitOptions.RemoveEmptyEntries ) != 0 )

           {

                  int s = 0;

                  int d = 0;

                  for( int i = 0; i < result.Length; ++i )

                  {

                         if( result[s].Length == 0 )

                         {

                               ++s;

                         }

                         else

                         {

                               result[d++] = result[s++];

                         }

                  }

                  Array.Resize( ref result, d );

           }

           return result;

    }


    • Edited by Viorel_MVP Friday, October 7, 2016 6:59 AM
    • Proposed as answer by cheong00Editor Friday, October 7, 2016 8:33 AM
    • Marked as answer by cheong00Editor Friday, October 14, 2016 6:47 AM
    Friday, October 7, 2016 6:57 AM