예제 #1
0
            public void Add(AsciiColumnType item)
            {
                switch (item)
                {
                case AsciiColumnType.DBNull:
                    _parent.Add(AsciiColumnInfo.DBNull);
                    break;

                case AsciiColumnType.Int64:
                    _parent.Add(AsciiColumnInfo.Integer);
                    break;

                case AsciiColumnType.Double:
                    _parent.Add(AsciiColumnInfo.FloatWithDecimalSeparator);
                    break;

                case AsciiColumnType.DateTime:
                    _parent.Add(AsciiColumnInfo.DateTime);
                    break;

                case AsciiColumnType.Text:
                    _parent.Add(AsciiColumnInfo.Text);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("item");
                }
            }
예제 #2
0
        public static AsciiLineStructure AssumeSeparator(int nLine, string sLine, string separator)
        {
            AsciiLineStructure tabStruc = new AsciiLineStructure();

            tabStruc.LineNumber = nLine;

            int len = sLine.Length;
            int ix  = 0;

            for (int start = 0; start <= len; start = ix + 1)
            {
                ix = sLine.IndexOf(separator, start, len - start);
                if (ix == -1)
                {
                    ix = len;
                }

                // try to interpret ix first as DateTime, then as numeric and then as string
                string substring = sLine.Substring(start, ix - start);
                if (ix == start) // just this char is a tab, so nothing is between the last and this
                {
                    tabStruc.Add(typeof(DBNull));
                }
                else if (IsNumeric(substring))
                {
                    tabStruc.Add(typeof(double));
                    tabStruc.AddToDecimalSeparatorStatistics(substring); // make a statistics of the use of decimal separator
                }
                else if (IsDateTime(substring))
                {
                    tabStruc.Add(typeof(System.DateTime));
                }
                else
                {
                    tabStruc.Add(typeof(string));
                }
            } // end for
            return(tabStruc);
        }
예제 #3
0
        /// <summary>
        /// Analyse the provided line of text with regard to one separation stragegy and returns the resulting structure.
        /// </summary>
        /// <param name="nLine">Line number.</param>
        /// <param name="tokens">The content of the line, already separated into tokens.</param>
        /// <param name="numberFormat">The number culture to use.</param>
        /// <param name="dateTimeFormat">The DateTime format culture to use.</param>
        /// <returns>The resulting structure.</returns>
        public static AsciiLineStructure GetStructure(int nLine, IEnumerable <string> tokens, System.Globalization.CultureInfo numberFormat, System.Globalization.CultureInfo dateTimeFormat)
        {
            var tabStruc = new AsciiLineStructure();

            foreach (string substring in tokens)
            {
                if (string.IsNullOrEmpty(substring)) // just this char is a tab, so nothing is between the last and this
                {
                    tabStruc.Add(AsciiColumnInfo.DBNull);
                }
                else if (IsNumeric(substring, numberFormat))
                {
                    if (IsIntegral(substring, numberFormat))
                    {
                        tabStruc.Add(AsciiColumnInfo.Integer);
                    }
                    else if (IsFloat(substring, numberFormat))
                    {
                        if (substring.Contains(numberFormat.NumberFormat.NumberDecimalSeparator))
                        {
                            tabStruc.Add(AsciiColumnInfo.FloatWithDecimalSeparator);
                        }
                        else
                        {
                            tabStruc.Add(AsciiColumnInfo.FloatWithoutDecimalSeparator);
                        }
                    }
                    else
                    {
                        tabStruc.Add(AsciiColumnInfo.GeneralNumber);
                    }
                }
                else if (IsDateTime(substring, dateTimeFormat))
                {
                    tabStruc.Add(AsciiColumnInfo.DateTime);
                }
                else
                {
                    tabStruc.Add(AsciiColumnInfo.Text);
                }
            } // end for
            return(tabStruc);
        }
예제 #4
0
    public static AsciiLineStructure AssumeSeparator(int nLine, string sLine, string separator)
    {
      AsciiLineStructure tabStruc = new AsciiLineStructure();
      tabStruc.LineNumber = nLine;

      int len =sLine.Length;
      int ix=0;
      for(int start=0; start<=len; start=ix+1)
      {
        ix = sLine.IndexOf(separator,start,len-start);
        if(ix==-1)
        {
          ix = len;
        }

        // try to interpret ix first as DateTime, then as numeric and then as string
        string substring = sLine.Substring(start,ix-start);
        if(ix==start) // just this char is a tab, so nothing is between the last and this
        {
          tabStruc.Add(typeof(DBNull));
        }
        else if(IsNumeric(substring))
        {
          tabStruc.Add(typeof(double));
          tabStruc.AddToDecimalSeparatorStatistics(substring); // make a statistics of the use of decimal separator
        }
        else if(IsDateTime(substring))
        {
          tabStruc.Add(typeof(System.DateTime));
        }
        else
        {
          tabStruc.Add(typeof(string));
        }
      } // end for
      return tabStruc;
    }
예제 #5
0
		/// <summary>
		/// Analyse the provided line of text with regard to one separation stragegy and returns the resulting structure.
		/// </summary>
		/// <param name="nLine">Line number.</param>
		/// <param name="tokens">The content of the line, already separated into tokens.</param>
		/// <param name="numberFormat">The number culture to use.</param>
		/// <param name="dateTimeFormat">The DateTime format culture to use.</param>
		/// <returns>The resulting structure.</returns>
		public static AsciiLineStructure GetStructure(int nLine, IEnumerable<string> tokens, System.Globalization.CultureInfo numberFormat, System.Globalization.CultureInfo dateTimeFormat)
		{
			AsciiLineStructure tabStruc = new AsciiLineStructure();

			foreach (string substring in tokens)
			{
				if (string.IsNullOrEmpty(substring)) // just this char is a tab, so nothing is between the last and this
				{
					tabStruc.Add(AsciiColumnInfo.DBNull);
				}
				else if (IsNumeric(substring, numberFormat))
				{
					if (IsIntegral(substring, numberFormat))
					{
						tabStruc.Add(AsciiColumnInfo.Integer);
					}
					else if (IsFloat(substring, numberFormat))
					{
						if (substring.Contains(numberFormat.NumberFormat.NumberDecimalSeparator))
							tabStruc.Add(AsciiColumnInfo.FloatWithDecimalSeparator);
						else
							tabStruc.Add(AsciiColumnInfo.FloatWithoutDecimalSeparator);
					}
					else
					{
						tabStruc.Add(AsciiColumnInfo.GeneralNumber);
					}
				}
				else if (IsDateTime(substring, dateTimeFormat))
				{
					tabStruc.Add(AsciiColumnInfo.DateTime);
				}
				else
				{
					tabStruc.Add(AsciiColumnInfo.Text);
				}
			} // end for
			return tabStruc;
		}