gpt4 book ai didi

string - 检查一个字符串是否包含另一个字符串

转载 作者:行者123 更新时间:2023-12-03 04:08:22 25 4
gpt4 key购买 nike

我想查找一个字符串中是否包含“,”(逗号)。除了逐个字符读取之外,我们还有其他选择吗?

最佳答案

使用Instr函数(找到旧版本的 MSDN 文档 here )

Dim pos As Integer

pos = InStr("find the comma, in the string", ",")

将在 pos 中返回 15

如果没有找到则返回0

如果您需要使用 Excel 公式查找逗号,可以使用 =FIND(",";A1) 函数。

请注意,如果您想使用 Instr 查找不区分大小写的字符串的位置,请使用 Instr 的第三个参数并为其指定 const vbTextCompare (或者只是1 为顽固分子)。

Dim posOf_A As Integer

posOf_A = InStr(1, "find the comma, in the string", "A", vbTextCompare)

将为您提供值 14。

请注意,在这种情况下,您必须按照我链接的规范中的说明指定起始位置:如果指定了比较,则需要起始参数。

关于string - 检查一个字符串是否包含另一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15585058/

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