从给定的字符串输入确定型 [英] Determine type from given string input

查看:105
本文介绍了从给定的字符串输入确定型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法来检测从给定的输入字符串类型?

例如:

string input = "07/12/1999";

string DetectType( s ) { .... }

Type t = DetectType(input); // which would return me the matched datatype. i.e. "DateTime" in this case.

请问我要从头开始写这个?
只是想检查是否有人知道一个更好的办法之前,我去了。

Would I have to write this from scratch?
Just wanted to check if anybody knows of a better way before I went about it.

谢谢!

推荐答案

我是pretty的肯定,你将不得不从头开始写这 - 部分是因为它的将是的非常的严格根据您的要求。即使是一个简单的问题,比如是否你给的日期是12月7日和7月12日可以有很大的区别就在这里......和你的日期格式是否严格,你所需要的数字格式支持等。

I'm pretty sure you'll have to write this from scratch - partly because it's going to be very strictly tailored to your requirements. Even a simple question such as whether the date you've given is December 7th or July 12th can make a big difference here... and whether your date formats are strict, what number formats you need to support etc.

我不认为我曾经遇到过类似的话 - 而且说实话,这种猜测常常让我很紧张。它可以是很难得到正确的解析,即使你知道的数据类型,更何况当你猜测的数据类型入手:(

I don't think I've ever come across anything similar - and to be honest, this sort of guesswork usually makes me nervous. It can be hard to get parsing right even when you know the data type, let alone when you're guessing at the data type to start with :(

这篇关于从给定的字符串输入确定型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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