using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace HuizhongLibrary
{
public class DataConvert
{
public static DateTime? ToDateTime(object val)
{
string value=Convert.ToString(val);
if (value == null || value == "") return null;
DateTime? dt = null;
try { dt = Convert.ToDateTime(value); }
catch { return null; }
return dt;
}
public static Int32? ToInt32(object val)
{
string value = Convert.ToString(val);
if (value == null || value == "") return null;
Int32? dt = null;
try { dt = Convert.ToInt32(value); }
catch { return null; }
return dt;
}
public static Decimal? ToDecimal(object val)
{
string value = Convert.ToString(val);
if (value == null || value == "") return null;
Decimal? dt = null;
try { dt = Convert.ToDecimal(value); }
catch { return null; }
return dt;
}
public static Double? ToDouble(object val)
{
string value = Convert.ToString(val);
if (value == null || value == "") return null;
Double? dt = null;
try { dt = Convert.ToDouble(value); }
catch { return null; }
return dt;
}
public static Single? ToSingle(object val)
{
string value = Convert.ToString(val);
if (value == null || value == "") return null;
Single? dt = null;
try { dt = Convert.ToSingle(value); }
catch { return null; }
return dt;
}
public static Int16? ToInt16(object val)
{
string value = Convert.ToString(val);
if (value == null || value == "") return null;
Int16? dt = null;
try { dt = Convert.ToInt16(value); }
catch { return null; }
return dt;
}
public static String ToString(object val)
{
string value = Convert.ToString(val);
if (value == null || value == "") return "";
return value.Trim();
}
#region 过滤网页标签
public static String CleanHTMLTag(string htmlStream)
{
if (!string.IsNullOrEmpty(htmlStream))
{
/*
* 最好把所有的特殊HTML标记都找出来,然后把与其相对应的Unicode字符一起影射到Hash表内,最后一起都替换掉
*/
//先单独测试,成功后,再把所有模式合并
//注:这两个必须单独处理
//去掉嵌套了HTML标记的JavaScript:()|(