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


C# __DTString.PeekCurrentWord方法代码示例

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


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

示例1: GetEra

        private static int GetEra(__DTString str, DateTimeResult result, ref DateTimeFormatInfo dtfi) {
            int[] eras = dtfi.Calendar.Eras;

            if (eras != null) {
                String word = str.PeekCurrentWord();
                int era;
                if ((era = dtfi.GetEra(word)) > 0) {
                    str.Index += word.Length;
                    return (era);
                }
                
                switch (dtfi.CultureID) {
                    case 0x0411:                    
                        // 0x0411 is the culture ID for Japanese.
                        if (dtfi.Calendar.ID != Calendar.CAL_JAPAN) {
                            // If the calendar for dtfi is Japanese, we have already
                            // done the check above. No need to re-check again.
                            GetJapaneseCalendarDTFI();                            
                            if ((era = m_jajpDTFI.GetEra(word)) > 0) {
                                str.Index += word.Length;
                                result.calendar = JapaneseCalendar.GetDefaultInstance();
                                dtfi = m_jajpDTFI;
                                return (era);
                            }
                        } 
                        break;
                   case 0x0404:
                        // 0x0404 is the culture ID for Taiwan.
                        if (dtfi.Calendar.ID != Calendar.CAL_TAIWAN) {
                            GetTaiwanCalendarDTFI();                            
                            if ((era = m_zhtwDTFI.GetEra(word)) > 0) {
                                str.Index += word.Length;
                                result.calendar = TaiwanCalendar.GetDefaultInstance();
                                dtfi = m_zhtwDTFI;
                                return (era);
                            }
                        } 
                        break;
                        
                }
            }
            return (-1);
        }
开发者ID:ArildF,项目名称:masters,代码行数:43,代码来源:datetimeparse.cs

示例2: GetMonthNumber

        //
        // Check the word at the current index to see if it matches a month name.
        // Return -1 if a match is not found. Otherwise, a value from 1 to 12 is returned.
        //
        private static int GetMonthNumber(__DTString str, DateTimeFormatInfo dtfi)
        {
            //
            // Check the month name specified in dtfi.
            //
            int i;

            int monthInYear = (dtfi.GetMonthName(13).Length == 0 ? 12 : 13);
            int maxLen = 0;
            int result = -1;
            int index;
            String word = str.PeekCurrentWord();

            //
            // We have to match the month name with the longest length, 
            // since there are cultures which have more than one month names
            // with the same prefix.
            //
            for (i = 1; i <= monthInYear; i++) {
                String monthName = dtfi.GetMonthName(i);

                if ((index = str.CompareInfo.IndexOf(
                    word, monthName, CompareOptions.IgnoreCase)) >= 0) {
                    // This condition allows us to parse the month name for:
                    // 1. the general cases like "yyyy MMMM dd".
                    // 2. prefix in the month name like: "dd '\x05d1'MMMM yyyy" (Hebrew - Israel)
                    result = i;
                    maxLen = index + monthName.Length;
                } else if (str.StartsWith(monthName, true)) {
                    // The condition allows us to get the month name for cultures
                    // which has spaces in their month names.
                    // E.g. 
                    if (monthName.Length > maxLen) {
                        result = i;
                        maxLen = monthName.Length;
                    }
                }
                }
            if (result > -1) {
                str.Index += maxLen;
                return (result);
            }
            for (i = 1; i <= monthInYear; i++)
            {
                if (MatchWord(str, dtfi.GetAbbreviatedMonthName(i), false))
                {
                    return (i);
                }
            }

            //
            // Check the month name in the invariant culture.
            //
            for (i = 1; i <= 12; i++)
            {
                if (MatchWord(str, invariantInfo.GetMonthName(i), false))
                {
                    return (i);
                }
            }

            for (i = 1; i <= 12; i++)
            {
                if (MatchWord(str, invariantInfo.GetAbbreviatedMonthName(i), false))
                {
                    return (i);
                }
            }

            return (-1);
        }
开发者ID:ArildF,项目名称:masters,代码行数:75,代码来源:datetimeparse.cs


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