2017-05-16 203 views
1

我試圖刪除單引號,但我不知道該怎麼做。 我在這裏留下相關的代碼。從輸入中刪除單引號

response.write "Original: " & rs2("comentario") 
comentario = Replace(rs2("comentario"), "ñ", "ñ") 
comentario = Replace(comentario, "ó", "ó") 
comentario = Replace(comentario, "fÆ", "ó") 
comentario = Replace(comentario, "³", "ó") 
comentario = Replace(comentario, "Ã", "") 
comentario = Replace(comentario, "Â", "") 
comentario = Replace(comentario, Chr(39), "") 
comentario = Replace(comentario, "'", "") 
comentario = Replace(comentario, "\'", "") 
response.write "<br>Modificado: " & comentario & "<br>-----------------------<br>" 

從上面的代碼的結果是這樣的

 
Original: reunión INNOVAE IÃ'igo Iñake 
Modificado: reunión INNOVAE I'igo Iñake 
----------------------- 
+3

你似乎有一個字符編碼問題。看看這篇文章https://www.hanselman.com/blog/InternationalizationAndClassicASP.aspx – John

+0

謝謝,它似乎被解決 –

回答

1

我解決了這個改變網頁的編碼部分從

<% 
CharSet = "ISO-8859-1" 
Response.CodePage = 28591 
%> 

<% 
Response.CodePage = 65001 
Response.CharSet = "utf-8" 
%> 

並將其保存爲UTF-8在記事本++

1

你正在試圖做的,或是遇到什麼問題,什麼目前尚不清楚給我。如果你想從字符串中刪除所有撇號(U + 0027),那麼你在做什麼

comentario = Replace(comentario, "'", "") 

應該工作得很好。 (並且使用chr(39)而不是"'"將是等效的

這可能是您要替換的字符實際上並不是一個撇號,但是其他一些類似外觀的字符也許您正在輸出在一個不支持字符串中實際字符的字符集中,它將被輸出中最接近的最佳匹配(這是一個U + 0027撇號)替換,最終你會看到這些。這些只是猜測,儘管,而且很難確切地知道,而不知道更多關於你的設置和你實際上想要做什麼。

在更大的圖片中,它看起來像你試圖以某種方式修復之前傳輸的數據錯誤的字符編碼除非你是tryi如果要修復過去以這種方式不可逆轉地損壞的數據,則最好糾正該問題,並確保您的數據在工作流程中的所有點都以正確的編碼進行傳輸。確保Response.CharSetResponse.CodePage的設置方式符合您希望使用的任何文本編碼方式,並確保您正確處理瀏覽器設置的編碼中的表單輸入。

+0

我試圖打印一個壞的保存在數據庫中的字符串。在數據庫中,這個字符串被保存爲reuni?nn INNOVAE?i?i?ake,並且我不知道如何刪除該撇號。 –

+0

您的評論中沒有撇號;你有一個U + 00B4急性口音。 –

1

這裏是我的固定創建有趣的人物:

我使用FN_CLEAN來清理用於數據庫插入/更新的東西:

function fn_clean(FixWhat) 
    if (isempty(FixWhat) or isnull(FixWhat) or FixWhat="") then 
     FixWhat="" 
    else 
     apos=chr(39) 
     quot=chr(34) 

     FixWhat=trim(FixWhat) 
     FixWhat=replace(FixWhat," "," ",1,-1,1) 
     FixWhat=replace(FixWhat,"''",apos & apos,1,-1,1) 
     FixWhat=replace(FixWhat,"'''",apos,1,-1,1) 

     FixWhat=replace(FixWhat,VBNullChar,"",1,-1,1) 
     FixWhat=replace(FixWhat,VBNullString,"",1,-1,1) 
     FixWhat=replace(FixWhat,VBTab," ",1,-1,1) 
     FixWhat=replace(FixWhat,VBVerticalTab," ",1,-1,1) 

     FixWhat=replace(FixWhat,"<ahref=","<a href=",1,-1,1) 
     FixWhat=replace(FixWhat,"<ahref =","<a href=",1,-1,1) 
     FixWhat=replace(FixWhat,"<imgsrc","<img src",1,-1,1) 
     FixWhat=replace(FixWhat,"<spanclass=","<span class=",1,-1,1) 
     FixWhat=replace(FixWhat,"<spanclass =","<span class=",1,-1,1) 
     FixWhat=replace(FixWhat,"//<![CDATA[","",1,-1,1) 
     FixWhat=replace(FixWhat,"//]]","",1,-1,1) 

     FixWhat=replace(FixWhat,"&amp;","&",1,-1,1) 
     FixWhat=replace(FixWhat,"amp;","&",1,-1,1) 
     FixWhat=replace(FixWhat,"&amp;","&",1,-1,1) 
     FixWhat=replace(FixWhat,"&&","&",1,-1,1) 
     FixWhat=replace(FixWhat,"&&","&",1,-1,1) 
     FixWhat=replace(FixWhat,"&lt;","<",1,-1,1)  
     FixWhat=replace(FixWhat,"&gt;",">",1,-1,1) 

     FixWhat=replace(FixWhat,"/","&#47;",1,-1,1) 
     'FixWhat=replace(FixWhat,"../../../images/","/images/",1,-1,1) 

     FixWhat=replace(FixWhat,"’",apos,1,-1,1) 
     FixWhat=replace(FixWhat,"’",apos,1,-1,1)   
     FixWhat=replace(FixWhat,"`",apos,1,-1,1) 
     'FixWhat=replace(FixWhat,chr(145),apos,1,-1,1) 
     'FixWhat=replace(FixWhat,chr(146),apos,1,-1,1) 
     'FixWhat=replace(FixWhat,chr(180),apos,1,-1,1) 
     'FixWhat=replace(FixWhat,chr(184),apos,1,-1,1) 

     FixWhat=replace(FixWhat,"_new","_BLANK",1,-1,1) 
     FixWhat=replace(FixWhat,"_NEW","_BLANK",1,-1,1) 

     'FixWhat=replace(FixWhat,"ñ","&#241;",1,-1,1) 

     'quotes  
     'FixWhat=replace(FixWhat,chr(132),quot,1,-1,1) 
     'FixWhat=replace(FixWhat,chr(147),quot,1,-1,1) 
     'FixWhat=replace(FixWhat,chr(148),quot,1,-1,1) 
     'FixWhat=replace(FixWhat,chr(152),quot,1,-1,1) 
     'FixWhat=replace(FixWhat,chr(168),quot,1,-1,1) 

     'hyphens 
     'FixWhat=replace(FixWhat,chr(150),"-",1,-1,1) 
     'FixWhat=replace(FixWhat,chr(151),"--",1,-1,1) 

     'dot dot dot 
     'FixWhat=replace(FixWhat,chr(133),"...",1,-1,1) 

     'line feed 
     'FixWhat=replace(FixWhat,chr(10),"[chr-10 was here]",1,-1,1) 
     'FixWhat=replace(FixWhat,chr(12),"[chr-12 was here]",1,-1,1) 
     'FixWhat=replace(FixWhat,chr(13),"[chr-13 was here]",1,-1,1) 

     'CR 
     'FixWhat=replace(FixWhat,chr(21),"<br>",1,-1,1) 

     'now for everything higher than char 128 
     'for i = 129 to 255 
     ' c = "&#" & i & ";" 
     ' FixWhat = replace(FixWhat,Chr(i),"&#39;",1,-1,1) 
     'next 

     'FixWhat=replace(FixWhat,quot,quot & quot) 

     'FixWhat=replace(FixWhat,"<br>" & vbCrLf & "<br>" & vbCrLf & "<br>" & vbCrLf,"<br>" & vbCrLf & "<br>" & vbCrLf,1,-1,1) 
     FixWhat=replace(FixWhat,vbCrLf & vbCrLf,vbCrLf,1,-1,1) 
     'FixWhat=replace(FixWhat,"<br><br><br><br>","<br><br>",1,-1,1) 
     'FixWhat=replace(FixWhat,"<br><br><br>","<br><br>",1,-1,1) 

     'FixWhat=replace(FixWhat,"<table><br>","<table>",1,-1,1) 
     'FixWhat=replace(FixWhat,"</td><br>","</td>",1,-1,1) 
     'FixWhat=replace(FixWhat,"<tr><br>","<tr>",1,-1,1) 
     'FixWhat=replace(FixWhat,"<br><tr>","<tr>",1,-1,1) 
     'FixWhat=replace(FixWhat,"</tr><br>","</tr>",1,-1,1) 
     'FixWhat=replace(FixWhat,"<br></tr>","</tr>",1,-1,1) 
     'FixWhat=replace(FixWhat,"<br><embed","<embed",1,-1,1) 
     'FixWhat=replace(FixWhat,"background=" & quot & " ","background=" & quot & quot & " ",1,-1,1) 

     FixWhat=replace(FixWhat,"alt =","title=",1,-1,1) 
     FixWhat=replace(FixWhat,"alt=","title=",1,-1,1) 
     FixWhat=replace(FixWhat,"alt= ","alt= ",1,-1,1) 
     FixWhat=replace(FixWhat,"alt= ","title=",1,-1,1) 
     FixWhat=replace(FixWhat,"title=" & chr(34) & chr(34),"title=image",1,-1,1) 
     FixWhat=replace(FixWhat,"title=" & chr(34) & chr(32),"title=image ",1,-1,1) 


     FixWhat=replace(FixWhat,"align=" & quot & " ","align=left ",1,-1,1) 
     FixWhat=replace(FixWhat,"border=" & quot & " "," ",1,-1,1) 
     FixWhat=replace(FixWhat,"this=" & quot & " "," ",1,-1,1) 
     FixWhat=replace(FixWhat,"width=" & quot & " ","width=10 ",1,-1,1) 
     FixWhat=replace(FixWhat,"x=" & quot & " "," ",1,-1,1) 

     FixWhat=replace(FixWhat,"[quote]","&#34;",1,-1,1) 
     FixWhat=replace(FixWhat,quot,"&#34;",1,-1,1) 
     FixWhat=replace(FixWhat,"'","&#39;",1,-1,1) 
    end if 
    fn_clean=FixWhat 
End Function 

,這一次我用「骯髒的IT UP FOR SCREEN /輸入框,ETC:

Function fn_dirty(FixWhat) 
    if (isnull(FixWhat) or FixWhat="") then 
     FixWhat="" 
    else 
     FixWhat=trim(FixWhat) 

     FixWhat=replace(FixWhat,"<ahref","<a href",1,-1,1) 

     FixWhat=replace(FixWhat,"<spanclass","<span class",1,-1,1) 

     'FixWhat=replace(FixWhat,"&#241;","ñ",1,-1,1) 

     FixWhat=replace(FixWhat," "," ",1,-1,1) 
     FixWhat=replace(FixWhat,"&#146;","'",1,-1,1) 
     FixWhat=replace(FixWhat,"&apos;","'",1,-1,1) 
     FixWhat=replace(FixWhat,"%27","'",1,-1,1) 
     FixWhat=replace(FixWhat,"&#39;","'",1,-1,1) 
     FixWhat=replace(FixWhat,"&#146;","'",1,-1,1) 
     FixWhat=replace(FixWhat,"&#47;","/",1,-1,1) 
     FixWhat=replace(FixWhat,"''''","'''",1,-1,1) 


     FixWhat=replace(FixWhat,"&#34;",chr(34),1,-1,1) 
     FixWhat=replace(FixWhat,"%22",chr(34),1,-1,1) 

     FixWhat=replace(FixWhat,chr(13) & chr(10),"",1,-1,1) 
     'FixWhat=replace(FixWhat,"&#10;" & "&#10;","",1,-1,1) 
     'FixWhat=replace(FixWhat,vbCrLf & vbCrLf,vbCrLf,1,-1,1) 
     'FixWhat=replace(FixWhat,chr(34)&chr(34)&chr(34),chr(34),1,-1,1) 
     'FixWhat=replace(FixWhat,chr(10),"[chr10 was here]",1,-1,1) 
     'FixWhat=replace(FixWhat,chr(12),"[chr12 was here]",1,-1,1) 
     'FixWhat=replace(FixWhat,chr(13),"[chr13 was here]",1,-1,1) 


     'FixWhat=replace(FixWhat,chr(34) & chr(34),chr(34),1,-1,1) 

     'FixWhat=replace(FixWhat,"alt='" & chr(32) & "'","alt=Put-image-title-here-instead-of-OceanMedia.net" & chr(32),1,-1,1) 
     'FixWhat=replace(FixWhat,"alt=" & chr(34) & chr(32) & chr(34),"title=Put-image-title-here-instead-of-OceanMedia.net" & chr(32),1,-1,1) 
     'FixWhat=replace(FixWhat,"alt='" & chr(32),"alt=Put-image-title-here-instead-of-OceanMedia.net" & chr(32),1,-1,1) 
     'FixWhat=replace(FixWhat,"alt='" & chr(32),"alt=Put-image-title-here-instead-of-OceanMedia.net" & chr(32),1,-1,1) 
     'FixWhat=replace(FixWhat,"alt=" & chr(34) & chr(32),"alt=Put-image-title-here-instead-of-OceanMedia.net" & chr(32),1,-1,1) 

     FixWhat=replace(FixWhat,"title=","alt=",1,-1,1) 
     'FixWhat=replace(FixWhat,"title='" & chr(32) & "'","title=Put-image-title-here-instead-of-OceanMedia.net" & chr(32),1,-1,1) 
     'FixWhat=replace(FixWhat,"title=" & chr(34) & chr(32) & chr(34),"title=Put-image-title-here-instead-of-OceanMedia.net" & chr(32),1,-1,1) 
     'FixWhat=replace(FixWhat,"title='" & chr(32),"title=Put-image-title-here-instead-of-OceanMedia.net" & chr(32),1,-1,1) 
     'FixWhat=replace(FixWhat,"title='" & chr(32),"title=Put-image-title-here-instead-of-OceanMedia.net" & chr(32),1,-1,1) 
     'FixWhat=replace(FixWhat,"title=" & chr(34) & chr(32),"title=Put-image-title-here-instead-of-OceanMedia.net" & chr(32),1,-1,1) 

     FixWhat=replace(FixWhat,"src=" & chr(34) & chr(32),"",1,-1,1) 
     FixWhat=replace(FixWhat,"src=" & chr(34) & "/images","src=" & chr(34) & "images",1,-1,1) 

     FixWhat=replace(FixWhat,"background=" & chr(34) & chr(32),"background=" & chr(34) & chr(34) & chr(32),1,-1,1) 



     FixWhat=replace(FixWhat,"x=" & chr(34) & chr(32)," ",1,-1,1) 

     FixWhat=replace(FixWhat,"&amp;","&",1,-1,1) 
     FixWhat=replace(FixWhat,"amp;","&",1,-1,1) 
     FixWhat=replace(FixWhat,"&amp;","&",1,-1,1) 
     FixWhat=replace(FixWhat,"&&","&",1,-1,1) 
     FixWhat=replace(FixWhat,"&&","&",1,-1,1) 
     FixWhat=replace(FixWhat,"&lt;","<",1,-1,1)  
     FixWhat=replace(FixWhat,"&gt;",">",1,-1,1) 

     'FixWhat=replace(FixWhat,"&amp;","&",1,-1,1) 
     FixWhat=replace(FixWhat,"//<![CDATA[","",1,-1,1) 
     FixWhat=replace(FixWhat,"//]]","",1,-1,1) 

     FixWhat=replace(FixWhat,"<TABLE","<table",1,-1,1)  
     FixWhat=replace(FixWhat,"<TBODY>","<tbody>",1,-1,1) 
     FixWhat=replace(FixWhat,"<TR","<tr",1,-1,1)    
     FixWhat=replace(FixWhat,"<TD","<td",1,-1,1) 
     FixWhat=replace(FixWhat,"</TR>","</tr>",1,-1,1)    
     FixWhat=replace(FixWhat,"</TD>","</td>",1,-1,1) 

     FixWhat=replace(FixWhat,"<html><br>","<html>",1,-1,1) 
     FixWhat=replace(FixWhat,"<head><br>","<head>",1,-1,1)  
     FixWhat=replace(FixWhat,"<body><br>","<body>",1,-1,1) 
     FixWhat=replace(FixWhat,"<br><tbody>","<tbody>",1,-1,1) 
     FixWhat=replace(FixWhat,"<tbody><br>","<tbody>",1,-1,1) 
     FixWhat=replace(FixWhat,"<br><tr>","<tr>",1,-1,1) 
     FixWhat=replace(FixWhat,"<tr><br>","<tr>",1,-1,1) 
     FixWhat=replace(FixWhat,"<br><td","<td",1,-1,1) 
     FixWhat=replace(FixWhat,"<br></html>","</html>",1,-1,1) 

     'FixWhat=replace(FixWhat,"#34;#34;#34;","&#34;&#34;",1,-1,1) 
     'FixWhat=replace(FixWhat,"#39;#39;#39;","&#39;&#39;",1,-1,1) 

     'FixWhat=replace(FixWhat,"&#34;&#34;&#34;","&#34;&#34;",1,-1,1) 
     'FixWhat=replace(FixWhat,"&#39;&#39;&#39;","&#39;&#39;",1,-1,1) 

    end if 
    fn_dirty=FixWhat 
End Function