在 ASP 中使用 Replace 處理資料庫欄位時,若欄位為 NULL 會拋出 Microsoft VBScript 運行時錯誤 '800a005e':無效使用 Null: 'Replace'。單純判斷 If str = "" Then 無效,因 NULL ≠ 空字串。
<%
If IsNull(rs("content")) Then
Response.Write "無內容"
Else
Response.Write Replace(rs("content"), vbCrLf, "<br/>")
End If
%>
<%
' 將 NULL 轉為空字串再處理,一行搞定
safeContent = "" & rs("content") ' 隱式轉換:NULL → ""
Response.Write Replace(safeContent, vbCrLf, "<br/>")
%>
<%
If IsNull(keyword) Then keyword = dxy_title
If IsNull(description) Then description = dxy_title
%>
IsNull() 是判斷 NULL 的唯一標準函數"" & Null 會安全返回空字串 ""DEFAULT '' 而非允許 NULL掌握 IsNull 與隱式轉換技巧,徹底告別 Replace 空指針崩潰。