本文整理汇总了C#中System.__DTString.StartsWith方法的典型用法代码示例。如果您正苦于以下问题:C# __DTString.StartsWith方法的具体用法?C# __DTString.StartsWith怎么用?C# __DTString.StartsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.__DTString
的用法示例。
在下文中一共展示了__DTString.StartsWith方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}