当前位置: 首页>>代码示例>>C#>>正文


C# __DTString.GetSubString方法代码示例

本文整理汇总了C#中System.__DTString.GetSubString方法的典型用法代码示例。如果您正苦于以下问题:C# __DTString.GetSubString方法的具体用法?C# __DTString.GetSubString怎么用?C# __DTString.GetSubString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.__DTString的用法示例。


在下文中一共展示了__DTString.GetSubString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseTimeZone

        /*=================================ParseTimeZone==========================
        **Action: Parse the timezone offset in the following format:
        **          "+8", "+08", "+0800", "+0800"
        **        This method is used by DateTime.Parse().
        **Returns:      The TimeZone offset.
        **Arguments:
        **      str the parsing string
        **Exceptions:
        **      FormatException if invalid timezone format is found.
        ============================================================================*/

        private static bool ParseTimeZone(ref __DTString str, ref TimeSpan result) {
            // The hour/minute offset for timezone.
            int hourOffset = 0;
            int minuteOffset = 0;
            DTSubString sub;

            // Consume the +/- character that has already been read
            sub = str.GetSubString();
            if (sub.length != 1) {
                return false;
            }
            char offsetChar = sub[0];
            if (offsetChar != '+' && offsetChar != '-') {
                return false;
            }
            str.ConsumeSubString(sub);

            sub = str.GetSubString();
            if (sub.type != DTSubStringType.Number) {
                return false;
            }
            int value = sub.value;
            int length = sub.length;
            if (length == 1 || length == 2) {
                // Parsing "+8" or "+08"
                hourOffset = value;
                str.ConsumeSubString(sub);
                // See if we have minutes
                sub = str.GetSubString();
                if (sub.length == 1 && sub[0] == ':') {
                    // Parsing "+8:00" or "+08:00"
                    str.ConsumeSubString(sub);
                    sub = str.GetSubString();
                    if (sub.type != DTSubStringType.Number || sub.length < 1 || sub.length > 2) {
                        return false;
                    }
                    minuteOffset = sub.value;
                    str.ConsumeSubString(sub);
                }
            }
            else if (length == 3 || length == 4) {
                // Parsing "+800" or "+0800"
                hourOffset = value / 100;
                minuteOffset = value % 100;
                str.ConsumeSubString(sub);
            }
            else {
                // Wrong number of digits
                return false;
            }
            Contract.Assert(hourOffset >= 0 && hourOffset <= 99, "hourOffset >= 0 && hourOffset <= 99");
            Contract.Assert(minuteOffset >= 0 && minuteOffset <= 99, "minuteOffset >= 0 && minuteOffset <= 99");
            if (minuteOffset < 0 || minuteOffset >= 60) {
                return false;
            }

            result = new TimeSpan(hourOffset, minuteOffset, 0);
            if (offsetChar == '-') {
                result = result.Negate();
            }
            return true;
        }
开发者ID:ChuangYang,项目名称:coreclr,代码行数:73,代码来源:DateTimeParse.cs

示例2: ParseTimeZone

		private static bool ParseTimeZone(ref __DTString str, ref TimeSpan result)
		{
			int hours = 0;
			int num = 0;
			DTSubString subString = str.GetSubString();
			if (subString.length != 1)
			{
				return false;
			}
			char c = subString[0];
			if (c != '+' && c != '-')
			{
				return false;
			}
			str.ConsumeSubString(subString);
			subString = str.GetSubString();
			if (subString.type != DTSubStringType.Number)
			{
				return false;
			}
			int value = subString.value;
			int length = subString.length;
			if (length == 1 || length == 2)
			{
				hours = value;
				str.ConsumeSubString(subString);
				subString = str.GetSubString();
				if (subString.length == 1 && subString[0] == ':')
				{
					str.ConsumeSubString(subString);
					subString = str.GetSubString();
					if (subString.type != DTSubStringType.Number || subString.length < 1 || subString.length > 2)
					{
						return false;
					}
					num = subString.value;
					str.ConsumeSubString(subString);
				}
			}
			else
			{
				if (length != 3 && length != 4)
				{
					return false;
				}
				hours = value / 100;
				num = value % 100;
				str.ConsumeSubString(subString);
			}
			if (num < 0 || num >= 60)
			{
				return false;
			}
			result = new TimeSpan(hours, num, 0);
			if (c == '-')
			{
				result = result.Negate();
			}
			return true;
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:60,代码来源:DateTimeParse.cs

示例3: ParseTimeZone

        private static bool ParseTimeZone(ref __DTString str, ref TimeSpan result)
        {
            int hours = 0;
            int minutes = 0;
            DTSubString subString = str.GetSubString();
            if (subString.length != 1)
            {
                return false;
            }
            char ch = subString[0];
            if ((ch != '+') && (ch != '-'))
            {
                return false;
            }
            str.ConsumeSubString(subString);
            subString = str.GetSubString();
            if (subString.type != DTSubStringType.Number)
            {
                return false;
            }
            int num3 = subString.value;
            int length = subString.length;
            switch (length)
            {
                case 1:
                case 2:
                    hours = num3;
                    str.ConsumeSubString(subString);
                    subString = str.GetSubString();
                    if ((subString.length == 1) && (subString[0] == ':'))
                    {
                        str.ConsumeSubString(subString);
                        subString = str.GetSubString();
                        if (((subString.type != DTSubStringType.Number) || (subString.length < 1)) || (subString.length > 2))
                        {
                            return false;
                        }
                        minutes = subString.value;
                        str.ConsumeSubString(subString);
                    }
                    break;

                default:
                    if ((length != 3) && (length != 4))
                    {
                        return false;
                    }
                    hours = num3 / 100;
                    minutes = num3 % 100;
                    str.ConsumeSubString(subString);
                    break;
            }
            if ((minutes < 0) || (minutes >= 60))
            {
                return false;
            }
            result = new TimeSpan(hours, minutes, 0);
            if (ch == '-')
            {
                result = result.Negate();
            }
            return true;
        }
开发者ID:randomize,项目名称:VimConfig,代码行数:63,代码来源:DateTimeParse.cs


注:本文中的System.__DTString.GetSubString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。