Example #1
0
 public static string[]  GetWordArray(string bufferToManage, char separator)
 {
     char    [] as8Separator = { separator };
     return(StringUtility.GetWordArray(bufferToManage, as8Separator));
 }
Example #2
0
        /// <summary>
        /// Convert a string to an array of words (use space & tabulation as separator)
        /// Quotes are managed here "word0 word1" will be 1 parameter
        /// </summary>
        public static string[]  GetWordArray2(string bufferToManage)
        {
            if (bufferToManage == null)
            {
                throw new NolmeArgumentNullException();
            }

            string[] ValueArray;
            int      ReadIndex, QuoteStart, QuoteEnd, NoQuoteEnd;
            int      SpaceAndTab;
            string   TemporaryString;

            char[]    SeparatorArray        = { ' ', (char)0x09 };
            ArrayList LocalElementArrayList = new ArrayList();

            if (!StringUtility.IsValid(bufferToManage))
            {
                ValueArray = new string [0];
                return(ValueArray);
            }

            // Check a quick case with no string inside
            QuoteStart = bufferToManage.IndexOf('\"');
            if (QuoteStart == -1)
            {
                // No string using quotes, only separated by space or tab
                ValueArray = StringUtility.GetWordArray(bufferToManage);
            }
            else
            {
                // convert bufferToManage to string[]
                ReadIndex = 0;
                while (ReadIndex < bufferToManage.Length)
                {
                    if (bufferToManage [ReadIndex] == '\"')
                    {
                        // separated by quotes, get end of quotes to retrieve datas
                        QuoteEnd = bufferToManage.IndexOf('\"', ReadIndex + 1);
                        if (QuoteEnd == -1)
                        {
                            QuoteEnd = bufferToManage.Length;
                        }
                        TemporaryString = bufferToManage.Substring(ReadIndex + 1, QuoteEnd - (ReadIndex + 1));

                        // Skip element found
                        ReadIndex += TemporaryString.Length + 2;                                // Add one to skip 2 quotes
                    }
                    else
                    {
                        // Not using quotes, only separated by space or tab
                        NoQuoteEnd = bufferToManage.IndexOfAny(SeparatorArray, ReadIndex + 1);
                        if (NoQuoteEnd == -1)
                        {
                            NoQuoteEnd = bufferToManage.Length;
                        }
                        TemporaryString = bufferToManage.Substring(ReadIndex, NoQuoteEnd - (ReadIndex));

                        // Skip element found
                        ReadIndex += TemporaryString.Length;
                    }

                    // Skip spaces & tabs
                    SpaceAndTab = ReadIndex;
                    while (SpaceAndTab < bufferToManage.Length)
                    {
                        if ((bufferToManage [SpaceAndTab] == ' ') || (bufferToManage [SpaceAndTab] == 0x09))
                        {
                            SpaceAndTab++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    ReadIndex = SpaceAndTab;

                    // Add element
                    LocalElementArrayList.Add(TemporaryString);
                }

                // Convert ArrayList to string[]
                ValueArray = new string [LocalElementArrayList.Count];
                for (int i = 0; i < LocalElementArrayList.Count; i++)
                {
                    ValueArray [i] = ((string)LocalElementArrayList[i]);
                }
            }
            return(ValueArray);
        }
Example #3
0
 /// <summary>
 /// Convert a string to an array of words (use space & tabulation as separator)
 /// </summary>
 public static string[]  GetWordArray(string bufferToManage)
 {
     char    [] as8Separator = { ' ', (char)0x09 };
     return(StringUtility.GetWordArray(bufferToManage, as8Separator));
 }