(求助)一个截取字符串的问题。
string a = "select * from GameCardNoInfo where and Nullity = 'false' and CardNo ='1' and UseDate between '1987-10-14 00:00:00' and '2000-1-1 00:00:00' and";此段SQL语句前后多余了 AND 怎么截取他们然后把AND去掉?? --------------------编程问答-------------------- 手动删了的了~。。。 --------------------编程问答-------------------- string.Join 方法,可以把一个字符串数组join起来。
如果你不用这个方法,
那就 a = a.Substring(0,a.Length-3) --------------------编程问答--------------------
--------------------编程问答-------------------- 前面和后面都多了 and --------------------编程问答-------------------- 楼主这语句是拼出来的吧,把and改下应该好搞定 --------------------编程问答-------------------- 其实这个比较简单, 你只要判断当前字符串是否以and 结尾
String..::.TrimEnd 方法 从当前 String 对象移除数组中指定的一组字符的所有尾部匹配项。
String a ="aaaand";
if (a.EndsWith("and"))
{
a = a.Substring(0, a.Length - 3);
Response.Write(a);
} --------------------编程问答-------------------- 在数据库里截取好像比较麻烦 --------------------编程问答-------------------- 楼主,拼SQL语句有问题,前面加上一个(1=1)+“ and ”+加上你拼上的语句就可以了 --------------------编程问答-------------------- 我只想知道如何用截取做。各位高手,请帮帮我撒。
--------------------编程问答-------------------- 搞半天,自己解决了。。
string sql1 = a.Substring(0, 35).ToString();
string sql2 = a.Substring(38, a.Length-41).ToString();
Response.Write(sql1+sql2 );
结贴。。 --------------------编程问答-------------------- 居然是手动截的 --------------------编程问答-------------------- 你确定你这样截取没有问题,这样灵活性好像不是很好吧 --------------------编程问答-------------------- 为什么要截取
string a = "select * from GameCardNoInfo where and Nullity = 'false' and CardNo ='1' and UseDate between '1987-10-14 00:00:00' and '2000-1-1 00:00:00' and";
a = a.Replace("and", "");
这样不就好了? --------------------编程问答-------------------- Sorry!! --------------------编程问答-------------------- 来晚了用substring --------------------编程问答--------------------
str1=select * from GameCardNoInfo where
str2=and Nullity = 'false' and CardNo ='1' and UseDate between '1987-10-14 00:00:00' and '2000-1-1 00:00:00' and
截取str2 中前后的 and
t.Trim(aa))
Dim aa(3) As Char
aa(0) = "a"
aa(1) = "n"
aa(2) = "d"
Response.Write(str2[code=VB.NET]
[/code] --------------------编程问答--------------------
Dim aa(3) As Char
aa(0) = "a"
aa(1) = "n"
aa(2) = "d"
Response.Write(str2.Trim(aa))
补充:.NET技术 , ASP.NET