string 格式:
['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am'],
['American Express Company',52.55,0.01,0.02,'9/1 12:00am'],
['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am'],
['AT&T Inc.',31.61,-0.48,-1.54,'9/1 12:00am']
['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am'],
['American Express Company',52.55,0.01,0.02,'9/1 12:00am'],
['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am'],
['AT&T Inc.',31.61,-0.48,-1.54,'9/1 12:00am']
解决方案 »
- 哪位朋友可以给我提供一个比较易懂的五子棋博奕的估值源代码
- 寻求做bbS信息提取的朋友
- 求解!
- 帮忙看一下,为什么报错,在线等!谢谢
- 有没有办法像 using namespace 一般引用类????
- sqlServer连接
- 建一个下在EXCEL模板的安钮,应该用什么命令???大侠,高手们请指点!!!!!
- 页面调用js问题
- C#当中如何才能判断用户是否处于全屏状态(例如游戏)
- 為什麼執行 "private Word.ApplicationClass WordApp = new Word.ApplicationClass();" 出問題
- C# WinForm 打包问题,急!!!
- c#如何模拟组合键(如ctrl+F)
或转化为xml
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("col1", typeof(string));
dt.Columns.Add("col2", typeof(decimal));
dt.Columns.Add("col3", typeof(decimal));
dt.Columns.Add("col4", typeof(decimal));
dt.Columns.Add("col5", typeof(string));
dt.Rows.Add(new object[] {"3m Co",71.72,0.02,0.03,"9/1 12:00am" });
dt.Rows.Add(new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, "9/1 12:00am" });
dt.Rows.Add(new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, "9/1 12:00am" });
ds.Tables.Add(dt);
#endregion string strTbl = ds.Tables[0].TableName;
StringBuilder sBld = new StringBuilder();
sBld.AppendFormat("<{0}>[^<]*", strTbl);
for (int i = 0; i < dt.Columns.Count; i++)
{
sBld.AppendFormat("<{0}>([^<]+)</{0}>[^<]*", dt.Columns[i].ColumnName);
}
sBld.AppendFormat("[^<]*</{0}>", strTbl);
string reg = sBld.ToString();
string s = ds.GetXml();
s = Regex.Replace(s, reg, "['${1}',${2},${3},${4},${5}],",RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"[^]]*</?\w+>[^[]*", "");
Response.Write(s);
#region test data
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("col1", typeof(string));
dt.Columns.Add("col2", typeof(decimal));
dt.Columns.Add("col3", typeof(decimal));
dt.Columns.Add("col4", typeof(decimal));
dt.Columns.Add("col5", typeof(string));
dt.Rows.Add(new object[] { "3m Co", 71.72, 0.02, 0.03, "9/1 12:00am" });
dt.Rows.Add(new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, "9/1 12:00am" });
dt.Rows.Add(new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, "9/1 12:00am" });
ds.Tables.Add(dt);
#endregion string strTbl = ds.Tables[0].TableName;
StringBuilder sBld = new StringBuilder();
sBld.AppendFormat(" <{0}>[^<]*", strTbl);
for (int i = 0; i < dt.Columns.Count; i++)
{
sBld.AppendFormat("<{0}>([^<]*)</{0}>[^<]*", dt.Columns[i].ColumnName);
}
sBld.AppendFormat("[^<]* </{0}>", strTbl);
string reg = sBld.ToString(); string s = ds.GetXml();
s = Regex.Replace(s, reg, "['${1}',${2},${3},${4},${5}],", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"[^]]*</?\w+>[^[]*", "");
Response.Write(s);
我试了,有空值的话,就不会往下了
DataTable dt = new DataTable();
dt.Columns.Add("col1", typeof(string));
dt.Columns.Add("col2", typeof(decimal));
dt.Columns.Add("col3", typeof(decimal));
dt.Columns.Add("col4", typeof(decimal));
dt.Columns.Add("col5", typeof(string)); dt.Rows.Add(new object[] { DBNull.Value, 71.72, 0.02, DBNull.Value, "9/1 12:00am" });
dt.Rows.Add(new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, "9/1 12:00am" });
dt.Rows.Add(new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, "9/1 12:00am" });
ds.Tables.Add(dt);
string strTbl = ds.Tables[0].TableName;
StringBuilder sBld = new StringBuilder();
sBld.AppendFormat(" <{0}>[^<]*", strTbl);
for (int i = 0; i < dt.Columns.Count; i++)
{
sBld.AppendFormat("(?:<{0}>)?([^<]*)(?:</{0}>)?[^<]*", dt.Columns[i].ColumnName);
}
sBld.AppendFormat("[^<]* </{0}>", strTbl);
string reg = sBld.ToString(); string s = ds.GetXml();
s = Regex.Replace(s, reg, "['${1}',${2},${3},${4},${5}],", RegexOptions.IgnoreCase);
s = Regex.Replace(s, @"[^]]*</?\w+>[^[]*", "");
Response.Write(s);