string constr = "data source=127.0.0.1;uid=sa;pwd=sa;database=pub;";
请问怎么从上面的字符串里抠出ip,用户,密码和数据库名?正则该怎么写?很迷糊
请问怎么从上面的字符串里抠出ip,用户,密码和数据库名?正则该怎么写?很迷糊
解决方案 »
- xml 读值
- C#怎么解决循环执行一个线程使用内存幅度过大.
- 高分求教:关于erp客户端服务器的架构
- 求toolstrip及toolsrtipContainer的使用方法说明
- 如何把richtextbox中的内容写入txt文件
- 如何删除和修改嵌入的资源文件???
- 崩溃,无法解决的:System.Runtime.InteropServices.COMException
- 求高手帮忙
- 求毕业设计项目(C# ASPNET)
- C#做的安装程序在安装的时候如何将一个文件安装到system32下,win2000可不一定安装到C盘啊
- 未经处理的异常: System.IO.FileNotFoundException: 未能加载文件或程序集“accessDA
- 【菜鸟求助】WinForm中的绘图问题
string r = Regex.Match(s, @"database=([^;]+)").Groups[1].Value;
Response.Write(r);
只要把database改成别的就可以取出各个部分。
string s = "data source=127.0.0.1;uid=sa;pwd=sa;database=pub;";
Dictionary<string, string> dictionary = s.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToDictionary(x => x.Split('=')[0], x => x.Split('=')[1]);
foreach (KeyValuePair<string, string> pair in dictionary)
Console.WriteLine(pair.Key + ":" + pair.Value);
Console.WriteLine("uid的值是:" + dictionary["uid"]);