读书人

ASP中怎么使用like

发布时间: 2012-02-17 17:50:41 作者: rapoo

ASP中如何使用like
if Rs("ContentType") = "%tsh%" Then


我的要求是如果一条记录的ContentType字段 包含了tsh字样, 则输出 Response.Write "你好"


应该怎么样实现?

[解决办法]

HTML code
Visual Basic Scripting Edition 语言参考 --------------------------------------------InStr 函数返回某字符串在另一字符串中第一次出现的位置。InStr([start, ]string1, string2[, compare])参数start可选项。数值表达式,用于设置每次搜索的开始位置。如果省略,将从第一个字符的位置开始搜索。如果 start 包含 Null,则会出现错误。如果已指定 compare,则必须要有 start 参数。string1必选项。接受搜索的字符串表达式。string2必选项。要搜索的字符串表达式。compare可选项。指示在计算子字符串时使用的比较类型的数值。有关数值,请参阅“设置”部分。如果省略,将执行二进制比较。设置compare 参数可以有以下值:常数 值 描述 vbBinaryCompare 0 执行二进制比较。 vbTextCompare 1 执行文本比较。 返回值InStr 函数返回以下值:如果 InStr 返回 string1 为零长度 0 string1 为 Null Null string2 为零长度 start string2 为 Null Null string2 没有找到 0 在 string1 中找到 string2 找到匹配字符串的位置 start > Len(string2) 0 说明下面的示例利用 InStr 搜索字符串:Dim SearchString, SearchChar, MyPosSearchString ="XXpXXpXXPXXP"   ' String to search in.SearchChar = "P"   ' Search for "P".MyPos = Instr(4, SearchString, SearchChar, 1)   ' A textual comparison starting at position 4. Returns 6.MyPos = Instr(1, SearchString, SearchChar, 0)   ' A binary comparison starting at position 1. Returns 9.    MyPos = Instr(SearchString, SearchChar)   ' Comparison is binary by default (last argument is omitted). Returns 9.MyPos = Instr(1, SearchString, "W")   ' A binary comparison starting at position 1. Returns 0 ("W" is not found).注意 InStrB 函数使用包含在字符串中的字节数据,所以 InStrB 返回的不是一个字符串在另一个字符串中第一次出现的字符位置,而是字节位置。要求版本 1请参阅InstrRev 函数--------------------------------------------© 2000 Microsoft Corporation 版权所有。保留所有权利。使用规定。
[解决办法]
HTML code
<%if InStr(Rs("ContentType"),"tsh")>0 thenResponse.Write("hello")end if%>
[解决办法]
HTML code
<%if InStr(Rs("ContentType")&"","tsh")>0 thenResponse.Write("hello")end if%>
[解决办法]
不是很明白你的意思
如果是在记录集中的话就这样if instr(Rs("ContentType"),"tsh")>0 Then
如是是在查询的时候的话sql="select * from 表 where ContentType like'%tsh%'"

读书人网 >ASP

热点推荐