如果声明基于'包含某个字符串'? [英] If statement based on 'contains a certain string'?

查看:92
本文介绍了如果声明基于'包含某个字符串'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以根据

传入表单下​​拉列表的值构建一个CDO.To语句,其中包含任何单词,例如ChangeStatus:


如何构造IF语句以隔离

传入变量中的''字符串''以允许分支语句:


如果Request.form(ChangeStatue)包含字符串Sales Alert,然后


''//

否则

''//


结束如果


它会使用类似Instr(Request.form(ChangeStatus),

" SalesAlert")那么
< br $>
To = ab*@cats.com


Else
To = db*@cats.com


结束如果


感谢这里的任何帮助!


谢谢

杰森

Is it possible to construct a CDO.To statement based on the value of an
incoming form drop down list which contains any word such as "ChangeStatus:"

How would I construct the IF statement to isolate the ''string'' in the
incoming variable to allow a branching statement:

If Request.form("ChangeStatue") containts the string "Sales Alert" Then

''//
Else
''//

End If

Would it use something like Instr(Request.form("ChangeStatus"),
"SalesAlert") Then

To = ab*@cats.com

Else
To= db*@cats.com

End If

Appreciate any help here!

Thanks
Jason

推荐答案

Instr返回一个整数,表示你正在寻找的字符串字符串中的[relative]起始

位置。示例。


Instr(cat,a)= 2

Instr(dog,a)= 0 ''''不存在


所以,如果值> gt; 0,然后找到它。


如果Instr(Request.Form(ChangeStatus),Sales Alert)> 0然后......


请注意,默认的比较方法是二进制,这意味着它的情况是

敏感。


InStr在线文档:
http://msdn.microsoft.com/library/en...vsfctInStr.asp

WSH在线文档:
http://msdn.microsoft.com/library/en .. .chnologies.asp


WSH文档下载:
http://www.microsoft.com/downloads/d...6-1C4099D7BBB9


更优雅的处理方式可能是:


sValue = UCase(Request.Form(ChangeStatus))


Select Case True

Case Instr(sValue,Sales Alert)> 0

'''做某事

Case Instr(sValue,Theft Alert)> 0

'''做别的事情

结束选择


-


雷在工作

Microsoft ASP / ASP.NET MVP

< ja *** @ catamaranco.com>在消息中写道

新闻:OZ ************** @ TK2MSFTNGP10.phx.gbl ...
Instr returns an integer representing the [relative] starting
position in a string of the string that you''re looking for. Example.

Instr("cat", "a") = 2
Instr("dog", "a") = 0 ''''doesn''t exist

So, if the value > 0, then it''s found.

If Instr(Request.Form("ChangeStatus"), "Sales Alert") > 0 Then...

Note that the default comparison method is binary, meaning it''s case
sensitive.

InStr Documentation Online:
http://msdn.microsoft.com/library/en...vsfctInStr.asp

WSH Documentation Online:
http://msdn.microsoft.com/library/en...chnologies.asp

WSH Documentation Download:
http://www.microsoft.com/downloads/d...6-1C4099D7BBB9

A more graceful way of handling your situation may be:

sValue = UCase(Request.Form("ChangeStatus"))

Select Case True
Case Instr(sValue, "Sales Alert") > 0
''''do something
Case Instr(sValue, "Theft Alert") > 0
''''do something else
End Select

--

Ray at work
Microsoft ASP/ASP.NET MVP
<ja***@catamaranco.com> wrote in message
news:OZ**************@TK2MSFTNGP10.phx.gbl...
是否有可能构建基于传入表单下​​拉列表的值
的CDO.To语句,其中包含任何单词,如
" ChangeStatus:"
如何构造IF语句以隔离
中的'string''允许分支声明的传入变量:

如果Request.form(ChangeStatue)包含字符串Sales Alert,
然后
''//
其他
'//

结束如果

它会使用像Instr这样的东西(Request.form(" ChangeStatus"),
" SalesAlert")然后

To = ab * @ cats .com

其他
To = db*@cats.com

结束如果

在这里感谢任何帮助!

Jason
Is it possible to construct a CDO.To statement based on the value of an incoming form drop down list which contains any word such as "ChangeStatus:"
How would I construct the IF statement to isolate the ''string'' in the incoming variable to allow a branching statement:

If Request.form("ChangeStatue") containts the string "Sales Alert" Then
''//
Else
''//

End If

Would it use something like Instr(Request.form("ChangeStatus"),
"SalesAlert") Then

To = ab*@cats.com

Else
To= db*@cats.com

End If

Appreciate any help here!

Thanks
Jason






谢谢Ray,但它似乎没有工作。


ChangeStatus = UCase(Request.Form(" ChangeStatus"))

Response.write"< br>< bR>" &安培; ChangeStatus& "< br>< br>"


''//销售阶段警告:正在提供


选择案例ChangeStatus


Case Instr(ChangeStatus,SALES)> 0

objMail.cc =" hu ** @ catamarans.com;

ba ***** @ catamarans.com,gi **** @ catamarans。 com, jo**********@catamarans.com
ga***@catamarans.com ol * ***@catamarans.com do***@catamarans.com "

Case Else

objMail.cc =" ba ***** @ catamarans.com,gi **** @ catamarans.com,
jo ********** @ catamarans.com ga *** @ catamarans.com ol **** @ catamarans.com
do***@catamarans.com "


结束选择


Ray写了
Thanks, Ray, but it does not appear to be working.

ChangeStatus = UCase(Request.Form("ChangeStatus"))
Response.write "<br><bR>" & ChangeStatus & "<br><br>"

''//SALES STAGE ALERT: Under Offer

Select Case ChangeStatus

Case Instr(ChangeStatus, "SALES") > 0
objMail.cc = "hu**@catamarans.com;
ba*****@catamarans.com,gi****@catamarans.com, jo**********@catamarans.com,
ga***@catamarans.com, ol****@catamarans.com, do***@catamarans.com"

Case Else
objMail.cc = "ba*****@catamarans.com,gi****@catamarans.com,
jo**********@catamarans.com, ga***@catamarans.com, ol****@catamarans.com,
do***@catamarans.com"

End Select

Ray Wrote

更优雅的处理方式可能是:

sValue = UCase(的Request.Form(QUOT; ChangeStatus" ))

Select Case True
Case Instr(sValue,Sales Alert)> 0
'''做一些事情
Case Instr(sValue,Theft Alert)> 0
'''做其他事情
结束选择

-

Ray在工作
Microsoft ASP / ASP.NET MVP

A more graceful way of handling your situation may be:

sValue = UCase(Request.Form("ChangeStatus"))

Select Case True
Case Instr(sValue, "Sales Alert") > 0
''''do something
Case Instr(sValue, "Theft Alert") > 0
''''do something else
End Select

--

Ray at work
Microsoft ASP/ASP.NET MVP



于2005年5月5日在microsoft.public.inetserver.asp.general上写道:
wrote on 05 jan 2005 in microsoft.public.inetserver.asp.general:
谢谢,Ray但它似乎没有起作用。

ChangeStatus = UCase(Request.Form(ChangeStatus))
Response.write"< br>< bR>" ; &安培; ChangeStatus& "< br>< br>"

'//销售阶段警告:正在提供

选择案例ChangeStatus

案例Instr(ChangeStatus,SALES)> 0
Thanks, Ray, but it does not appear to be working.

ChangeStatus = UCase(Request.Form("ChangeStatus"))
Response.write "<br><bR>" & ChangeStatus & "<br><br>"

''//SALES STAGE ALERT: Under Offer

Select Case ChangeStatus

Case Instr(ChangeStatus, "SALES") > 0




以上是不符合逻辑的,应该是:


Select Case True

案例Instr(ChangeStatus,SALES)> 0


=====================

更好用..then..else ..,

这样可以减少初学者的错误:


如果Instr(ChangeStatus,SALES)> 0然后

...

否则

...

结束如果

-

Evertjan。

荷兰。

(用我的电子邮件地址替换所有带点的十字架)



The above is not logical and should be:

Select Case True
Case Instr(ChangeStatus, "SALES") > 0

=====================

even better use if..then..else..,
That gives less mistakes for the beginner:

If Instr(ChangeStatus, "SALES") > 0 then
...
Else
...
End If

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)


这篇关于如果声明基于'包含某个字符串'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆