String contains only a given set of characters

前端 未结 7 1464
执笔经年
执笔经年 2021-02-18 13:22

I need to know if a given string is a valid DateTime format string because the string may represent other things. I tried DateTime.ParseExact(somedate.ToString(format), format)

7条回答
  •  渐次进展
    2021-02-18 13:55

    There's a new project, NLib, which can do this much faster:

    if (input.IndexOfNotAny(new char[] { 'y', 'm', 'd', 's', 'h' }, StringComparison.OrdinalIgnoreCase) < 0)
    {
        // Valid
    }
    

提交回复
热议问题