Code
1.用户输入: 名称 = '量' And 类型 = '值' (或者双引号也行) 得到 名称 like '%量%' And 类型 like '%值%'
由于SuperMap 中 数据源类型不同 模糊查询 的通配符也不同
string strFileType = ini.GetIniStr("DataBaseSet", "FileType", "\\set", SoIniEdit.ControlIni.RootType.nRootDefalut);
switch (strFileType)
{
case "file":
// strQueryOptions = strQuery.Replace("=", "like");
// strQuery .Substring (
f = "*";
break ;
case "SQL+":
f = "%";
break ;
case "SQL":
f = "%";
break ;
case "ORACLE":
f = "%";
break;
default :
f = "*";
break ;
}
int nStart = -1; int nEnd = 0;
int lenth = strQuery.Length;
string sa;
string sa1;
int nStart1 = -1; int nEnd1 = 0;
int lenth1 = strQuery.Length;
string sb;
string sb1;
int c = strQuery.IndexOf("'", 0);
int d = strQuery.IndexOf("\"", 0);
if (c > 0)
{
for (int i = 0; i < strQuery.Length; i++)
{
nStart = strQuery.IndexOf("'", nStart + 1);
nEnd = strQuery.IndexOf("'", nStart + 1);
sa = strQuery.Substring(nStart + 1, nEnd - nStart - 1);
sa1 = f + sa + f;
strQuery = strQuery.Replace(sa, sa1);
nStart = nEnd + 2;
if (nStart >= lenth - 1) break;
}
}
if (d > 0)
{
for (int i = 0; i < strQuery.Length; i++)
{
nStart1 = strQuery.IndexOf("\"", nStart1 + 1);
nEnd1 = strQuery.IndexOf("\"", nStart1 + 1);
sb = strQuery.Substring(nStart1 + 1, nEnd1 - nStart1 - 1);
sb1 = f + sb + f;
strQuery = strQuery.Replace(sb, sb1);
nStart1 = nEnd1 + 2;
if (nStart1 >= lenth - 1) break;
}
}
// strQuery = strQuery.Replace("\\", " ");
strQuery = strQuery.Replace("\"","'");
objQueryDef.Filter = strQuery .Replace ("="," like ");
2. 分割字符串
"横图=1\02=竖图\03=sss\0\0\0\0\0" 得到“=”前后的东西,
string[] ss = new string[bufLen];
string s = Encoding.GetEncoding(0).GetString(buffer);
aa = s.Substring(0, bufLen);//aa: "横图=1\02=竖图\03=sss\0\0\0\0\0" 然后对aa进行分割,很烦咧
string[] sa = new string[aa.Length];// aa.Length=20
int c;
int d=0;
int z;
for ( z = 0; z <= aa.Length; z++)
{
c = aa.IndexOf("=",d); //c 从第d个位置开始出现“=”的位置, c=2
d = aa.IndexOf("\0",d+2);//
if (c == -1) break;
ss[z] = aa.Substring(c+1, d - c - 1);//ss[0]=1
}
int b = z;
string[] sz = new string[b];//知道Z的大小后,把ss[z]赋值给一个z大小合适的数组
for (int zz = 0; zz <b; zz++)
{
sz[zz] = ss[zz];
}
return sz ;
3。分割一句话中有多个 , 得到查询字段
string strField = Common.strField;
if (strField != "")
{
string[] ss = strField.Split(new char[] { ',' });//////////////////////分割, 得到查询字段
for (int a = 0; a < ss.Length-1; a++)
objQueryDef.Fields.Add(ss[a]);
}
分成三个字符串后,后面一个为空 不要啦
strField.Substring(1,2);
C#统计子字符串出现次数2008-08-02 16:51C#中没有统计子字符串出现次数的函数,那么如何在C#求出字符串中某字符的出现次数,比如求“ADSFGEHERGASDF”中“A”出现的次数。首先想到的方法当然是从头遍历字符串并统计:
c1 = 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] == 'A')
{
c1++;
}
}
第二种方法也很容易想到,将字符串中所有要查找的字符去除,然后比较去除前后的字符串长度即可。这种方法遭到了某人的鄙视,据说性能很差而且多占空间。
c2 = str.Length - str.Replace("A", String.Empty).Length;
接下来某人又提出了第三种方法,是用要查找的字符为分隔符,将原字符串分隔为多个子串,然后求子串的数目即可。在C#中这是一个写起来很短的方法:
c3 = str.Split(new char[] { 'A' }).Length - 1;
附 字符串的处理
using System;
using System.Collections.Generic;
using System.Text;
namespace 字符串的处理
{
class Program
{
static void Main(string[] args)
{
string str1 = "abcdefa";
string str2 = "abcde";
string str3 = "aBc";
string str4 = "abc";
//比较字符串
//Compare方法
Console.WriteLine("Compare方法");
Console.WriteLine(String.Compare(str1,str2));
Console.WriteLine(String.Compare(str3, str1));
Console.WriteLine(String.Compare(str3, str4));
Console.WriteLine(String.Compare(str1, str2, false));
Console.WriteLine(String.Compare(str4, 1, str3, 1, 2));
//CompareTo方法
Console.WriteLine("CompareTo方法");
Console.WriteLine(str1.CompareTo(str2));
Console.WriteLine(str2.CompareTo(str1));
//Equals方法
Console.WriteLine("Equals方法");
Console.WriteLine(str1.Equals(str2));
Console.WriteLine(str1.Equals(str1));
Console.WriteLine(String.Equals(str1,str2));
//定位字符串
//StartWith/EndsWith方法
Console.WriteLine("StartWith/EndsWith方法");
Console.WriteLine(str1.StartsWith("cb"));
Console.WriteLine(str1.EndsWith("f"));
//IndexOf/LastIndexOf方法
Console.WriteLine("IndexOf/LastIndexOf方法");
Console.WriteLine(Convert.ToString(str1.IndexOf('b')));
Console.WriteLine(Convert.ToString(str1.LastIndexOf('a')));
//IndexOfAny/LastIndexOfAny方法
Console.WriteLine("IndexOfAny/LastIndexOfAny方法");
char[] anyof={'c','b'};
Console.WriteLine(Convert.ToString(str1.IndexOfAny(anyof)));
Console.WriteLine(Convert.ToString(str1.LastIndexOfAny(anyof)));
//截取字符串
//Substring方法
Console.WriteLine("Substring方法");
string str5 = "";
str5 = str1.Substring(2, 3);
Console.WriteLine(str5);
//插入和填充字符
Console.WriteLine("插入和填充字符");
Console.WriteLine(str1.Insert(1,"ab"));
string str6 = "hello";
Console.WriteLine(str6.PadLeft(10,'@'));
Console.WriteLine(str6.PadRight(10, mailto:%20@));
//删除和剪切字符串
Console.WriteLine("删除和剪切字符串");
string strB = "ABCDEF";
Console.WriteLine(strB.Remove(1,2));
//复制字符串
Console.WriteLine("复制字符串");
string stra = "abc";
string strb = "";
char[] strc=new char[100];
strb = string.Copy(stra);
stra.CopyTo(1, strc, 0, 2);
Console.WriteLine(strc);
Console.WriteLine(strb);
//替换字符串
Console.WriteLine("替换字符串");
string strD = "Hello";
string strF = strD.Replace("ll", "r");
Console.WriteLine(strF);
Console.ReadLine();
}
}
1.用户输入: 名称 = '量' And 类型 = '值' (或者双引号也行) 得到 名称 like '%量%' And 类型 like '%值%'
由于SuperMap 中 数据源类型不同 模糊查询 的通配符也不同
string strFileType = ini.GetIniStr("DataBaseSet", "FileType", "\\set", SoIniEdit.ControlIni.RootType.nRootDefalut);
switch (strFileType)
{
case "file":
// strQueryOptions = strQuery.Replace("=", "like");
// strQuery .Substring (
f = "*";
break ;
case "SQL+":
f = "%";
break ;
case "SQL":
f = "%";
break ;
case "ORACLE":
f = "%";
break;
default :
f = "*";
break ;
}
int nStart = -1; int nEnd = 0;
int lenth = strQuery.Length;
string sa;
string sa1;
int nStart1 = -1; int nEnd1 = 0;
int lenth1 = strQuery.Length;
string sb;
string sb1;
int c = strQuery.IndexOf("'", 0);
int d = strQuery.IndexOf("\"", 0);
if (c > 0)
{
for (int i = 0; i < strQuery.Length; i++)
{
nStart = strQuery.IndexOf("'", nStart + 1);
nEnd = strQuery.IndexOf("'", nStart + 1);
sa = strQuery.Substring(nStart + 1, nEnd - nStart - 1);
sa1 = f + sa + f;
strQuery = strQuery.Replace(sa, sa1);
nStart = nEnd + 2;
if (nStart >= lenth - 1) break;
}
}
if (d > 0)
{
for (int i = 0; i < strQuery.Length; i++)
{
nStart1 = strQuery.IndexOf("\"", nStart1 + 1);
nEnd1 = strQuery.IndexOf("\"", nStart1 + 1);
sb = strQuery.Substring(nStart1 + 1, nEnd1 - nStart1 - 1);
sb1 = f + sb + f;
strQuery = strQuery.Replace(sb, sb1);
nStart1 = nEnd1 + 2;
if (nStart1 >= lenth - 1) break;
}
}
// strQuery = strQuery.Replace("\\", " ");
strQuery = strQuery.Replace("\"","'");
objQueryDef.Filter = strQuery .Replace ("="," like ");
2. 分割字符串
"横图=1\02=竖图\03=sss\0\0\0\0\0" 得到“=”前后的东西,
string[] ss = new string[bufLen];
string s = Encoding.GetEncoding(0).GetString(buffer);
aa = s.Substring(0, bufLen);//aa: "横图=1\02=竖图\03=sss\0\0\0\0\0" 然后对aa进行分割,很烦咧
string[] sa = new string[aa.Length];// aa.Length=20
int c;
int d=0;
int z;
for ( z = 0; z <= aa.Length; z++)
{
c = aa.IndexOf("=",d); //c 从第d个位置开始出现“=”的位置, c=2
d = aa.IndexOf("\0",d+2);//
if (c == -1) break;
ss[z] = aa.Substring(c+1, d - c - 1);//ss[0]=1
}
int b = z;
string[] sz = new string[b];//知道Z的大小后,把ss[z]赋值给一个z大小合适的数组
for (int zz = 0; zz <b; zz++)
{
sz[zz] = ss[zz];
}
return sz ;
3。分割一句话中有多个 , 得到查询字段
string strField = Common.strField;
if (strField != "")
{
string[] ss = strField.Split(new char[] { ',' });//////////////////////分割, 得到查询字段
for (int a = 0; a < ss.Length-1; a++)
objQueryDef.Fields.Add(ss[a]);
}
分成三个字符串后,后面一个为空 不要啦
strField.Substring(1,2);
C#统计子字符串出现次数2008-08-02 16:51C#中没有统计子字符串出现次数的函数,那么如何在C#求出字符串中某字符的出现次数,比如求“ADSFGEHERGASDF”中“A”出现的次数。首先想到的方法当然是从头遍历字符串并统计:
c1 = 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] == 'A')
{
c1++;
}
}
第二种方法也很容易想到,将字符串中所有要查找的字符去除,然后比较去除前后的字符串长度即可。这种方法遭到了某人的鄙视,据说性能很差而且多占空间。
c2 = str.Length - str.Replace("A", String.Empty).Length;
接下来某人又提出了第三种方法,是用要查找的字符为分隔符,将原字符串分隔为多个子串,然后求子串的数目即可。在C#中这是一个写起来很短的方法:
c3 = str.Split(new char[] { 'A' }).Length - 1;
附 字符串的处理
using System;
using System.Collections.Generic;
using System.Text;
namespace 字符串的处理
{
class Program
{
static void Main(string[] args)
{
string str1 = "abcdefa";
string str2 = "abcde";
string str3 = "aBc";
string str4 = "abc";
//比较字符串
//Compare方法
Console.WriteLine("Compare方法");
Console.WriteLine(String.Compare(str1,str2));
Console.WriteLine(String.Compare(str3, str1));
Console.WriteLine(String.Compare(str3, str4));
Console.WriteLine(String.Compare(str1, str2, false));
Console.WriteLine(String.Compare(str4, 1, str3, 1, 2));
//CompareTo方法
Console.WriteLine("CompareTo方法");
Console.WriteLine(str1.CompareTo(str2));
Console.WriteLine(str2.CompareTo(str1));
//Equals方法
Console.WriteLine("Equals方法");
Console.WriteLine(str1.Equals(str2));
Console.WriteLine(str1.Equals(str1));
Console.WriteLine(String.Equals(str1,str2));
//定位字符串
//StartWith/EndsWith方法
Console.WriteLine("StartWith/EndsWith方法");
Console.WriteLine(str1.StartsWith("cb"));
Console.WriteLine(str1.EndsWith("f"));
//IndexOf/LastIndexOf方法
Console.WriteLine("IndexOf/LastIndexOf方法");
Console.WriteLine(Convert.ToString(str1.IndexOf('b')));
Console.WriteLine(Convert.ToString(str1.LastIndexOf('a')));
//IndexOfAny/LastIndexOfAny方法
Console.WriteLine("IndexOfAny/LastIndexOfAny方法");
char[] anyof={'c','b'};
Console.WriteLine(Convert.ToString(str1.IndexOfAny(anyof)));
Console.WriteLine(Convert.ToString(str1.LastIndexOfAny(anyof)));
//截取字符串
//Substring方法
Console.WriteLine("Substring方法");
string str5 = "";
str5 = str1.Substring(2, 3);
Console.WriteLine(str5);
//插入和填充字符
Console.WriteLine("插入和填充字符");
Console.WriteLine(str1.Insert(1,"ab"));
string str6 = "hello";
Console.WriteLine(str6.PadLeft(10,'@'));
Console.WriteLine(str6.PadRight(10, mailto:%20@));
//删除和剪切字符串
Console.WriteLine("删除和剪切字符串");
string strB = "ABCDEF";
Console.WriteLine(strB.Remove(1,2));
//复制字符串
Console.WriteLine("复制字符串");
string stra = "abc";
string strb = "";
char[] strc=new char[100];
strb = string.Copy(stra);
stra.CopyTo(1, strc, 0, 2);
Console.WriteLine(strc);
Console.WriteLine(strb);
//替换字符串
Console.WriteLine("替换字符串");
string strD = "Hello";
string strF = strD.Replace("ll", "r");
Console.WriteLine(strF);
Console.ReadLine();
}
}