String []插入数据库 [英] String [] insert to database

查看:109
本文介绍了String []插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string [] st = time =2016-08-28 14:04:32id =8888name =Manikworkcode =0status =0



如何分开数据?

time = 2016-08-28 14:04:32;

id = 8888;

name = Manik;和workcode = 0;





如何解决这个问题并保存到数据库???



AB Masud



我的尝试:



char [] splitchar = {'='};







label1.Text = strArr [0];

label2.Text = strArr [1];

label3.Text = strArr [2];

label4.Text = strArr [3];

label5.Text = strArr [4];

label6.Text = strArr [5];

label7。 Text = strArr [6];

label8.Text = strArr [7];

label8.Text = strArr [8];

解决方案

使用正则表达式:

  public   static  Regex regex =  new 正则表达式(
time = \\\(?< Time>。+?)\\\ +?\\\\ + \\\\\ = = \\\(?< ID>。+?)\\\ \\\\ + \\\\ n +
name \\ = \\\(?< Name>。+?)\\\ \\\\ + \\\\\\\\\ span>(?< Workcode> +
。+?)\\\ \\\ \\\\ + \\\\\\\ = = \\\(?< Status> ;。+?)\\\
RegexOptions.Multiline
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);



然后,您可以按名称提取所需的部分。


string [] st=time="2016-08-28 14:04:32" id="8888" name="Manik" workcode="0" status="0"

how to separate data ?
time=2016-08-28 14:04:32;
id=8888;
name=Manik; and workcode=0;


how to solve this problem and save to database???

AB Masud

What I have tried:

char[] splitchar = { '=' };



label1.Text = strArr[0];
label2.Text = strArr[1];
label3.Text = strArr[2];
label4.Text = strArr[3];
label5.Text = strArr[4];
label6.Text = strArr[5];
label7.Text = strArr[6];
label8.Text =strArr[7];
label8.Text = strArr[8];

解决方案

Use a regex:

public static Regex regex = new Regex(
      "time=\\\"(?<Time>.+?)\\\"+?\\s+\r\nid=\\\"(?<ID>.+?)\\\"\\s+\r\n"+
      "name\\=\\\"(?<Name>.+?)\\\"\\s+\r\nworkcode\\=\\\"(?<Workcode>"+
      ".+?)\\\"\\s+\r\nstatus\\=\\\"(?<Status>.+?)\\\"",
    RegexOptions.Multiline
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );


You can then extract the parts you need by name.


这篇关于String []插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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