作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我的字符串是
my_string="MY PET IS CAT "
我也有一个数组
my_animals=Array ("CAT","DOG","LION")
由于数组 (CAT) 中的字符串之一位于 my_string 中,因此我希望将 CAT 放入变量中。
我们怎样才能做到呢?
最佳答案
Dim my_string As String, my_animals As Variant, element As Variant, variable as String
my_string = "MY PET IS CAT "
my_animals = Array("CAT", "DOG", "LION")
For Each element In my_animals
If InStr(my_string, element) Then
variable = element
End If
Next element
关于vba - Excel VBA : To store 'a word in a string' into a variable if that word is there in an array of strings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31117033/
我是一名优秀的程序员,十分优秀!