gpt4 book ai didi

vba - Excel VBA : To store 'a word in a string' into a variable if that word is there in an array of strings

转载 作者:行者123 更新时间:2023-12-02 10:43:16 25 4
gpt4 key购买 nike

假设我的字符串是

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com