在内容上传到数据库时用Replace把空格换成 ,
如:str=Replace(str," "," ")
在做查询程序时,同样的将查询字符串也用Replace做同样处理,这样就可以达到空格数一致了

解决方案 »

  1.   

    不不止是空格,引号,反斜杠等都有类似的问题,尤其是单引号,有时在sql语句里面会被解释。
    你可疑手工把这些特殊字符替换掉(我就是这么做的),也可以在处理时通通escape,在显示时才unescape了再显示。
      

  2.   

    <!--#include file="char.asp"-->
    <% 
    jcmc=request.cookies("jcmc")
    response.cookies("zmc")=HTMLEncode(request("zmc"))
       zmc=request.cookies("zmc")
       response.cookies("zmc1")=request("zmc1")
       zmc1=request.cookies("zmc1")
    if request("tj")="提交" then 
       zmc2=request("zmc2")
       if request("html")="支持HTML" then
       zjs=request("zjs")
       else
       zjs=HTMLEncode(request("zjs"))
       end if
        'set rsl= conn.execute ("select max(ISN_Z) as one from "& jcmc &"_Z ")
        'zbh = rsl("one")+1
    if zjs<>"没有内容" and zmc<>"" then
    set rs1=conn.Execute( "insert into " & jcmc & "_Z(mc,js) values('" & zmc & "','" & zjs & "')")
    else
    set rs1=conn.Execute( "update "& jcmc &"_Z set js='" & zjs & "',mc='"& zmc2 &"' where mc='" & zmc1 & "'")   
       end if
       end if 
      'response.write request.cookies("zmc")
    %>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link rel="stylesheet" href="css.css" type="text/css">
    <script language="JavaScript">
    <!--
    function MM_reloadPage(init) {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
    // -->
    </script>
    <script language="JavaScript">function check(){
    var s=document.form1.zmc.value
    if (s=="" ) 
      {alert("章名称不能为空")
         return false;}

    if (s.indexOf(" ")!=-1){
     alert("章名称不能有空格");
     return false;}
     return true;
     }
      function check1()
     { 
    if(form1.zmc1.value==""){
         alert("请选择章名称!");
    return false;
    }
    return true ;
    }
    </script>
    </head><body bgcolor="#FFFFFF" text="#000000">
    <form name="form1" method="post" action="">
      <div id="Layer2" style="position:absolute; left:4px; top:2px; width:601px; height:348px; z-index:2"> 
        <table width="99%" class="inputnormal">
          <tr> 
            <td colspan="4" height="2"><a href="jclr1.asp">教材录入</a> &gt;&gt;&gt; 章录入 
              &gt;&gt;&gt; <a href="jclr3.asp">节录入</a> </td>
          </tr>
          <tr> 
            <td width="20%" height="0" readonly class="inputnormal">请输入章的名称: </td>
            <td height="2" readonly class="inputnormal" colspan="2" rowspan="2"> 
              <div align="left"> 
      <% set rs1=conn.execute("select * from "& jcmc &"_Z  where mc='"& zmc1 &"'")
          if request("xg")="查看" then %>
      <input type="text" name="zmc2"  value="<%=rs1("mc")%>"size="40" onBlur="this.className='inputnormal0'" onFocus="this.className='inputedit';" class="inputnormal0">
                 <% else %>
    <input type="text" name="zmc" size="40" onBlur="this.className='inputnormal0'" onFocus="this.className='inputedit';" class="inputnormal0">
                  <% end if %>
        <select name="zmc1" class="list2" onchange="submit()">
                  <% if request("tj")="提交" then
     zmc1="" 
     response.write "<option  selected>—请选择—</option>"
     end if %>
                  <% 
    if (request("xg")="查看" or request("zmc1")<>"") and zmc1<>"" then
    response.write  "<option value="& zmc1 &">" & zmc1 & "</option>"
    else 
    response.write "--请选择--"
    end if %>
               
                  <% sql="select * from "& jcmc &"_Z "
          rs.open sql,conn,3,2
          do while not rs.eof %>
                  <option value="<%=rs("MC")%>"><%=rs("MC")%></option>
                  <% rs.movenext
          loop
          rs.close %>
                </select>
              </div>
            </td>
            <td height="0" readonly class="inputnormal" width="35%">&nbsp;</td>
          </tr>
          <tr>
            <td width="20%" height="0" readonly class="inputnormal">请选择章的名称:</td>
            <td height="0" readonly class="inputnormal" width="35%">章录入简要说明: </td>
          </tr>
          <tr> 
            <td height="21" class="inputnormal" width="20%" >请输入章的简介:</td>
            <td width="34%" height="21" readonly class="inputnormal" colspan="2"> 
              <div align="left">
                <input name="html" type="checkbox" value="支持HTML"><font color="#FF0000">支持HTML</font></div>
            </td>
            <td height="21" class="inputnormal" width="35%">1.录入:首先输入章的名称,如有</td>
          </tr>
          <tr> 
            <td colspan="3" height="22" readonly class="inputnormal" rowspan="10"> 
             <textarea name="zjs" cols="53" onBlur="this.className='inputnormal0'" onFocus="this.className='inputedit'" class="inputnormal0" rows="16"><%
     if request("xg")="查看" then
     'response.write "select js  from "&jcmc&"_Z  where mc='"& zmc1 &"'"
     'response.end
    set rs1=conn.execute("select js  from "&jcmc&"_Z  where mc='"& zmc1 &"'")
    if not (rs1.eof and rs1.bof) then
    response.write rs1("js")
    else 
    response.write "没有内容"
    end if
    end if
    %>
    </textarea>
            </td>
            <td width="34%" height="24" readonly class="inputnormal">简介则输入后,按&quot;提交&quot;进入</td>
          </tr>
          <tr> 
            <td width="34%" height="24" readonly class="inputnormal">&quot;节录入&quot;;否则,直接&quot;提交&quot;进入</td>
          </tr>
          <tr> 
            <td width="34%" height="24" readonly class="inputnormal">&quot;节录入&quot;即可。 
              如果&quot;选择章&quot;中</td>
          </tr>
          <tr> 
            <td width="34%" height="25" readonly class="inputnormal">有你要录入的章,直接选择后,如有</td>
          </tr>
          <tr> 
            <td width="34%" height="25" readonly class="inputnormal">简介输入后&quot;提交&quot;再&quot;节录入&quot;,</td>
          </tr>
          <tr> 
            <td width="34%" height="25" readonly class="inputnormal">否则选择后,直接&quot;节录入&quot;即可。</td>
          </tr>
          <tr> 
            <td width="34%" height="25" readonly class="inputnormal">2.查看:如&quot;课程录入&quot;的&quot;查看&quot;;</td>
          </tr>
          <tr> 
            <td width="34%" height="25" readonly class="inputnormal">只是&quot;选择课程&quot;替换为&quot;选择章&quot;. 
            </td>
          </tr>
          <tr> 
            <td width="34%" height="2" readonly class="inputnormal">&nbsp; </td>
          </tr>
          <tr> </tr>
          <tr> 
            <td colspan="4" height="22" readonly class="inputnormal"> 
              <input type="submit" name="xg" value="查看" onClick="return check1()" style="width:60;height:20;background-color: #FFFFFF; border: 1 solid #808080">
      &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
              <input type="submit" name="tj" value="提交" onClick="return check()"  style="width:60;height:20;background-color: #FFFFFF; border: 1 solid #808080">
              &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
              <input type="reset" name="Submit2" value="重置" style="width:60;height:20;background-color: #FFFFFF; border: 1 solid #808080" >
            </td>
          </tr>
        </table>
      </div>
    </form>
    </body>
    </html>
      

  3.   

    以上是我的一个网页的代码。
    我怎样用replace替换啊。怎样去判断空格的个数啊。
    如果数据库中以有zmc的数据,且不知道空格的个数那怎样替换啊。
    且能正确用zmc来做为条件来查徇
    谢谢
      

  4.   

    zmc=Replace(zmc," ","&nbsp;")将这句加在zmc存入数据库之前
    他的意思是将zmc中所有的" "都转化为"&nbsp,所以你没有必要统计空格数"
    数据库中已有的数据的空格数已经改变了,好象不能再变回来了,你只有将程序改好后重新录入
      

  5.   

    chr(41377)表示两个空格,在浏览器里可以显示,如果空格很多用这个表示连续的空格
    保存到数据库中
    1、text=replace(text,chr(41377),"  ")
    或者
    2、text=repalce(text," ","&nbsp;")
    从数据库中读出后
    1、text=replace(text,"  ",chr(41377))
    第2种就不需要替换,如果是修改,那就替换
    text=repalce(text,"&nbsp;"," ")