|
发表于 2020-12-23 10:30:02
|
显示全部楼层
public static string sqlConnectionString = "packet size=4096;user id=sa;data source=" + "." + ";persist security info=True;initial catalog=plan;password=aaa";
方案1。
string[] str = sqlConnectionString.Split( new char[]{'=',':'});
for(int i= 0;i<str.Lenght;i++
{
switch(str[i])
{
case "user id":
username=str[i+1];i++;break;
case"password":
pwd=str[i+1];i++;break;
default:
break;
}
}
方案2。
username = "user id=";
pwd="password=";
int pos1 = sqlCOnnectionString.Find(username);
int pos2 = sqlCOnnectionString.Find(";",pos1);
username = sqlCOnnectionString.SubString(pos1+username.Length,pos2);
pwd ....
方案3。
正则//MSDN不在,写不出来了
|
|