用这个函数就可以搞定!!试试看!!
<%!
synchronized public static String strHtml2DB(String string) throws Exception
//Use this method to validate a String before write it in SQL sentences
{
if (string == null || string.equals(""))
{
return string;
}
String str = string;
int index = 0;
for (index = str.indexOf("'", index); index != -1; index = str.indexOf("'", index +2))
{
str = str.substring(0, index) + "'" + str.substring(index);
}
return str;
}
%>
<%!
synchronized public static String strHtml2DB(String string) throws Exception
//Use this method to validate a String before write it in SQL sentences
{
if (string == null || string.equals(""))
{
return string;
}
String str = string;
int index = 0;
for (index = str.indexOf("'", index); index != -1; index = str.indexOf("'", index +2))
{
str = str.substring(0, index) + "'" + str.substring(index);
}
return str;
}
%>
能够给讲解一下?这个函数怎么使用?
str=strHtml2DB(str)?
String repl(String sstr,String fstr,String repstr)
{
//替换字符串函数
String tmpstr="";
int x = sstr.AnsiPos(fstr);
if(x==0)
{
tmpstr=sstr;
//Application->MessageBoxA(sstr.c_str(),"",MB_OK); //未找到查找字串,原样返回
return tmpstr;
}
while(x != 0)
{
tmpstr +=sstr.SubString(1,x-1) + repstr;
sstr = sstr.SubString(x+fstr.Length(),sstr.Length());
x = sstr.AnsiPos(fstr);
}
tmpstr+=sstr;
//Application->MessageBoxA(tmpstr.c_str(),"",MB_OK);
return tmpstr;
}
//---------------------------------------------
String sqlstr(String sqlstr)
{
//
if(sqlstr!="")
{
sqlstr=repl(sqlstr,"'","''");
}
return sqlstr;
}
//-------------------------------------