увлекся немного альтернативным прецедентом, чтобы обеспечить более прямой ответьте здесь метод, в котором ваша строка countrycodes остается строкой, и мы просто смотрим, находится ли подстрока в этой строке. Чтобы обеспечить всю подстроку, я использую разделители (те, что внутри вашей строки), чтобы огибать строку поиска и поиска.
CountryCodes = "99,115,218,305"
ThisCountry = "99"
Function Envelop(string)
Envelop = "," & string & ","
End Function
Function InString(substring, string)
Instring = (Instr(Envelop(string), Envelop(substring)) > 0)
End Function
If InString(ThisCountry, CountryCodes) Then
Wscript.Echo ThisCountry & " is in the string"
Else
Wscript.Echo ThisCountry & " is not in the string"
End If
Не NB часть ответа, но так как я все мои скрипты также в Рубине здесь версию Ruby. В Ruby проверка и печать могут быть Oneliner
country_codes = "99,115,218,305"
this_country = "99"
puts "#{this_country} is " + (",#{country_codes},"[",#{this_country},"] ? "" : "not") + " in the string"
ИЛИ используя регулярное выражение
puts "#{this_country} is #{(country_codes.match(/\b#{this_country}\b/) ? "" : "not")} in the string"
Некоторых explenation: в строках, заключенных с ""
#{}
вставляют код внутри, он является мощным средством конкатенирования. .match(/\b#{this_country}\b/)
использует регулярные expresion, чтобы соответствовать строке, заключенный в //
, в этом случае переменная this_country
Не знаю, если это возможно, или ваш случай использования, но посмотрите на следующий код, надеюсь, что это полезно ..
Вы можете использовать словарь кодов стран и имен и использовать его как это ..
Set Countries = CreateObject("scripting.dictionary")
With Countries
.Add "99", "Some Country"
.Add "115", "Some other Country"
.Add "218", "Still Some Country"
.Add "305", "Another Country"
End With
Sub ShowCountry(code)
code = Cstr(code)
For Each country in Countries
If Countries.Item(code) > "" Then
Wscript.Echo Countries.Item(code)
Exit Sub
End If
Next
Wscript.Echo "Country with code " & code & " doesn't exist"
End Sub
ShowCountry 115 'Some other Country'
ShowCountry 9 'Country with code 9 doesn't exist'
Опять же здесь версию Ruby,
Countries = {99 => "Some Country", 115 => "Some other Country", 218 => "Still Some Country", 305 => "Another Country"}
def show_country code
puts Countries[code] || "Country with code #{code} doesn't exist"
end
show_country 115 # Some other Country
show_country 9 #Country with code 9 doesn't exist
Это Visual Basic? – melpomene
есть. пытаясь поместить это в веб-приложение Classic ASP – Brasciole
Что такое 'iCountryArray'? Это строка? – melpomene