在 VBScript 中搜索字符串以验证是否包含字符 [英] Search a string in VBScript to verify if contains a character
问题描述
我想看看一个字符串是否包含一个点.
I am trying to see if a string contains a dot.
Set Root_Currency = Root_TaxDataSummary.SlvObject("Currency")
curr_val = InStr(Root_Currency,".")
If curr_val.exist Then
pass
else
fail
我的处理方式有什么问题吗?
Is there anything wrong with the way I am going about this?
推荐答案
InStr
返回一个整数,表示可以在字符串中找到搜索文本的位置.
InStr
returns an integer representing the position the searched text can be found in the string.
curr_val.exist
将不起作用,因为整数类型没有 exist
方法.相反:
curr_val.exist
won't work because the integer type doesn't have an exist
method. Instead:
If curr_val > 0 Then
或者(如果这是该变量的唯一用途):
Or (if this is the only use of that variable):
If InStr(Root_Currency,".") > 0 Then
最后,因为 0 在 VBScript 中被视为 False,所以您不需要包含相等性.要么找到角色的位置,要么返回 0/false:
Lastly, because 0 is treated as False in VBScript, you don't need to include the equality. Either a position is found for the character or you get back a 0/false:
If InStr(Root_Currency,".") Then
这篇关于在 VBScript 中搜索字符串以验证是否包含字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!