解析的最佳设计 [英] best design for parse

查看:72
本文介绍了解析的最佳设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我说我必须处理各种日期格式,我给格式字符串

来自以下之一

dd / mm / yyyy

mm / dd / yyyy

dd / mmm / yyyy

mmm / dd / yyyy

dd / mm / yy
mm / dd / yy

dd / mmm / yy

mmm / dd / yy

dd / mm
为传入格式提供相关正则表达式的最佳方法是什么

string

a)使用两个数组并静态匹配

b)使用正则表达式查找订单

let say I have to deal with various date format and I am give format string
from one of the following
dd/mm/yyyy
mm/dd/yyyy
dd/mmm/yyyy
mmm/dd/yyyy
dd/mm/yy
mm/dd/yy
dd/mmm/yy
mmm/dd/yy
dd/mm
what is the best way to come up a relevant regex for the incoming format
string
a) use two array and statically match
b) use regex to find the order

推荐答案

" gs" < gs@dontMail.telusschrieb:
"gs" <gs@dontMail.telusschrieb:

假设我必须处理各种日期格式并且我要格式化

string from one以下

dd / mm / yyyy

mm / dd / yyyy

dd / mmm / yyyy

mmm / dd / yyyy

dd / mm / yy

mm / dd / yy

dd / mmm / yy

mmm / dd / yy

dd / mm

为传入格式提供相关正则表达式的最佳方法

string
let say I have to deal with various date format and I am give format
string from one of the following
dd/mm/yyyy
mm/dd/yyyy
dd/mmm/yyyy
mmm/dd/yyyy
dd/mm/yy
mm/dd/yy
dd/mmm/yy
mmm/dd/yy
dd/mm
what is the best way to come up a relevant regex for the incoming format
string



也许您正在寻找''DateTime.ParseExact''。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http:// dotnet。 mvps.org/dotnet/faqs/>

Maybe you are looking for ''DateTime.ParseExact''.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


谢谢你,我希望能给你一个机会。它会照顾我需要的大部分内容,或者至少让其余的更容易。除了一件事,


我正在处理字符串数据行(最多300行)和日期字段

位置可能在手前不知道虽然对于给定的一组行,

他们留在同一个地方99.999的时间除了奇怪的评论

这不是那么关键;


" Herfried K. Wagner [MVP]" < hi *************** @ gmx.atwrote in message

news:eT ************** @ TK2MSFTNGP03.phx.gbl ...
thank you, I give that a shot Hopefully . it will take care most of what I
need, or at least make the rest easier. except one thing,

I am dealing with lines of string data (up to 300 lines) and the date fields
position may not be known before hand although for a given set of lines,
they stay in the same place 99.999 of the time except for the odd comments
which is not that critical;

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:eT**************@TK2MSFTNGP03.phx.gbl...

" gs" < gs@dontMail.telusschrieb:
"gs" <gs@dontMail.telusschrieb:

假设我必须处理各种日期格式并且我要格式化

string from one以下

dd / mm / yyyy

mm / dd / yyyy

dd / mmm / yyyy

mmm / dd / yyyy

dd / mm / yy

mm / dd / yy

dd / mmm / yy

mmm / dd / yy

dd / mm

为传入格式提供相关正则表达式的最佳方法

string
let say I have to deal with various date format and I am give format
string from one of the following
dd/mm/yyyy
mm/dd/yyyy
dd/mmm/yyyy
mmm/dd/yyyy
dd/mm/yy
mm/dd/yy
dd/mmm/yy
mmm/dd/yy
dd/mm
what is the best way to come up a relevant regex for the incoming format
string



也许您正在寻找''DateTime.ParseExact''。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http:// dotnet。 mvps.org/dotnet/faqs/>


Maybe you are looking for ''DateTime.ParseExact''.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



GS,


也许你能来吗?在2007年避免这种情况以及所有类似的东西作为

DateTime.parseExact,但是看看微软内部很好的建议

glob alization和相关的ToString选项。


Cor


" gs" < gs@dontMail.telusschreef在bericht

新闻:Ot ************** @ TK2MSFTNGP03.phx.gbl ...
GS,

Maybe can you avoid this in 2007 and all things like that as
DateTime.parseExact, but have a look to the nicely by Microsoft inbuild
globalization and than the to that related ToString option.

Cor

"gs" <gs@dontMail.telusschreef in bericht
news:Ot**************@TK2MSFTNGP03.phx.gbl...

让我说我必须处理各种日期格式并且我给出格式

字符串来自以下之一

dd / mm / yyyy

mm / dd / yyyy

dd / mmm / yyyy

mmm / dd / yyyy

dd / mm / yy

mm / dd / yy

dd / mmm / yy

mmm / dd / yy

dd / mm

为传入格式提供相关正则表达式的最佳方法

string

a)使用两个数组和静态匹配

b)使用正则表达式查找订单
let say I have to deal with various date format and I am give format
string from one of the following
dd/mm/yyyy
mm/dd/yyyy
dd/mmm/yyyy
mmm/dd/yyyy
dd/mm/yy
mm/dd/yy
dd/mmm/yy
mmm/dd/yy
dd/mm
what is the best way to come up a relevant regex for the incoming format
string
a) use two array and statically match
b) use regex to find the order



这篇关于解析的最佳设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆