using System; using System.Collections; using System.Text.RegularExpressions;public class MyClass { public static void Main() { string sSQL= "id='1' and name='aa' and sex = '女'"; string pattern = "id\\s*=\\s*\'(?<id>.*)\'\\s+and\\s+name\\s*=\\s*\'(?<name>.*)\'\\s+and\\s+sex\\s*=\\s*\'(?<sex>.*\')"; Regex r = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); Match m; for (m = r.Match(sSQL); m.Success; m = m.NextMatch()) { for(int i=0;i<m.Groups.Count;i++) Console.WriteLine("Value" + i.ToString() + ":" + m.Groups[i].Value); } RL(); }
string sSQL= "id='1' and name='aa' and sex = '女'"; string sql = sSQL.Replace("and", "*"); string[] ss = sql.Split(new char[] {'*'}); string aa = ""; int i = 0; IList n = new ArrayList(); IList m = new ArrayList(); foreach(string s in ss) { aa = s.Replace(" ","");
using System.Collections;
using System.Text.RegularExpressions;public class MyClass
{
public static void Main()
{
string sSQL= "id='1' and name='aa' and sex = '女'";
string pattern = "id\\s*=\\s*\'(?<id>.*)\'\\s+and\\s+name\\s*=\\s*\'(?<name>.*)\'\\s+and\\s+sex\\s*=\\s*\'(?<sex>.*\')";
Regex r = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
Match m;
for (m = r.Match(sSQL); m.Success; m = m.NextMatch())
{
for(int i=0;i<m.Groups.Count;i++)
Console.WriteLine("Value" + i.ToString() + ":" + m.Groups[i].Value);
}
RL();
}
private static void WL(string text, params object[] args)
{
Console.WriteLine(text, args);
}
private static void RL()
{
Console.ReadLine();
}
private static void Break()
{
System.Diagnostics.Debugger.Break();
}
}
string sql = sSQL.Replace("and", "*");
string[] ss = sql.Split(new char[] {'*'});
string aa = "";
int i = 0;
IList n = new ArrayList();
IList m = new ArrayList();
foreach(string s in ss)
{
aa = s.Replace(" ","");
n.Add(aa.Substring(0,aa.IndexOf("=")));
m.Add(aa.Substring(aa.IndexOf("'")+1,aa.Length-aa.IndexOf("'")-2));
Response.Write(n[i].ToString()+"="+m[i].ToString()+"#");
i=i+1;
}