我们如何实现双向字符流?比如说:
的
插入到字符流中,但是用户想要在上面的流的开头插入另一个字符:
人
所以这里开始插入TimeSpan start = TimeSpan.Parse("20:00:00");
TimeSpan end = TimeSpan.Parse("08:00:00");
TimeSpan now = DateTime.Now.TimeOfDay;
if (now.IsBetween(start, end))
{
Console.WriteLine("Between 20 to 8");
}
else
{
Console.WriteLine("Not Between 20 and 8");
}
Console.WriteLine("Time remaining before 8 AM is: {0} Hrs.",
(now.Hours > start.Hours) ? TimeSpan.Parse("24:00:00").Subtract(now).Add(end).Hours :
end.Subtract(now).Hours); //TimeSpan.Parse("24:00:00") is to compensate midnight hours.
public static class Extensions
{
public static bool IsBetween(this TimeSpan timeNow, TimeSpan start, TimeSpan end)
{
var time = timeNow;
// If the start time and the end time is in the same day.
if (start <= end)
return time >= start && time <= end;
// The start time and end time is on different days.
return time >= start || time <= end;
}
}
。然后用户想要添加另一个结束:
真
此外,只要在流中插入字符,就需要系统处理,因此首先处理m
,然后an
,然后man
。< / p>
注意:如果任何其他帖子看起来适合这个,或者它是否以某种方式重复,请告诉我。