本文整理汇总了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;
}
示例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;
}
示例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;
}