If 语句检查以特定数字开头的字符串
If statement check for a string start with a specific number
我想检查数据是否以 "01"
开头(意味着它是一个 phone 数字),我想在 phone 数字前面添加 "60"
并将字符串中的破折号替换为空。
我在这一行收到这个错误 if Field Like "01*" Then
Microsoft VBScript runtime error '800a0023'
Sub or Function not defined
希望有人能告诉我哪里出了问题。
<%Option Explicit%>
<%
Dim strConn, strScriptName,strSQL
strConn = Application("eDSNSMS")
strSQL = Request.querystring("SQL")
sub Write_CSV_From_Recordset(RS)
if RS.EOF then
exit sub
end if
dim RX
set RX = new RegExp
RX.Pattern = "\r|\n|,|"""
dim i
dim Field
dim Separator
do until RS.EOF
Separator = ""
for i = 0 to RS.Fields.Count - 1
Field = RS.Fields(i).Value & ""
if RX.Test(Field) then
Field = """" & Replace(Field, """", """""") & """"
end if
if Field Like "01*" Then
Field = "60" + Field
Field = """" & Replace(Field, "-", "") & """"
end if
Response.Write Separator & Field
Separator = ","
next
Response.Write vbNewLine
RS.MoveNext
loop
end sub
Dim objRS, objConn
set objConn = server.CreateObject("ADODB.Connection")
objConn.ConnectionString = strConn
objConn.Open
set objRS = server.CreateObject("ADODB.RecordSet")
objRS.Open strSQL, strConn, 0, 1
Write_CSV_From_Recordset objRS
Response.ContentType = "text/csv"
Response.AddHeader "Content-Disposition", "attachment;filename=export.csv"
%>
VBScript 没有 VBA 和 VB6 中的 Like
运算符。您必须使用其他方法测试您的字符串。
例如,您可以更改:
if Field Like "01*" Then
收件人:
If Left(Field, 2) = "01" Then
此外,您应该使用 &
来连接字符串,尤其是在处理可以被视为数字的值时,就像您在这里:
Field = "60" + Field
否则你 运行 求和 而不是 连接 的风险。
我想检查数据是否以 "01"
开头(意味着它是一个 phone 数字),我想在 phone 数字前面添加 "60"
并将字符串中的破折号替换为空。
我在这一行收到这个错误 if Field Like "01*" Then
Microsoft VBScript runtime error '800a0023'
Sub or Function not defined
希望有人能告诉我哪里出了问题。
<%Option Explicit%>
<%
Dim strConn, strScriptName,strSQL
strConn = Application("eDSNSMS")
strSQL = Request.querystring("SQL")
sub Write_CSV_From_Recordset(RS)
if RS.EOF then
exit sub
end if
dim RX
set RX = new RegExp
RX.Pattern = "\r|\n|,|"""
dim i
dim Field
dim Separator
do until RS.EOF
Separator = ""
for i = 0 to RS.Fields.Count - 1
Field = RS.Fields(i).Value & ""
if RX.Test(Field) then
Field = """" & Replace(Field, """", """""") & """"
end if
if Field Like "01*" Then
Field = "60" + Field
Field = """" & Replace(Field, "-", "") & """"
end if
Response.Write Separator & Field
Separator = ","
next
Response.Write vbNewLine
RS.MoveNext
loop
end sub
Dim objRS, objConn
set objConn = server.CreateObject("ADODB.Connection")
objConn.ConnectionString = strConn
objConn.Open
set objRS = server.CreateObject("ADODB.RecordSet")
objRS.Open strSQL, strConn, 0, 1
Write_CSV_From_Recordset objRS
Response.ContentType = "text/csv"
Response.AddHeader "Content-Disposition", "attachment;filename=export.csv"
%>
VBScript 没有 VBA 和 VB6 中的 Like
运算符。您必须使用其他方法测试您的字符串。
例如,您可以更改:
if Field Like "01*" Then
收件人:
If Left(Field, 2) = "01" Then
此外,您应该使用 &
来连接字符串,尤其是在处理可以被视为数字的值时,就像您在这里:
Field = "60" + Field
否则你 运行 求和 而不是 连接 的风险。