Use the Instr function
(使用Instr功能)
Dim pos As Integer
pos = InStr("find the comma, in the string", ",")
will return 15 in pos
(将返回15 in pos)
If not found it will return 0
(如果没有找到它将返回0)
If you need to find the comma with an excel formula you can use the =FIND(",";A1)
function.
(如果需要使用excel公式查找逗号,可以使用=FIND(",";A1)
函数。)
Notice that if you want to use Instr
to find the position of a string case-insensitive use the third parameter of Instr and give it the const vbTextCompare
(or just 1 for die-hards).
(请注意,如果要使用Instr
来查找不区分大小写的字符串的位置,请使用Instr
的第三个参数,并为其提供const vbTextCompare
(或者仅为1表示顽固分子)。)
Dim posOf_A As Integer
posOf_A = InStr(1, "find the comma, in the string", "A", vbTextCompare)
will give you a value of 14.
(会给你14的价值。)
Note that you have to specify the start position in this case as stated in the specification I linked: The start argument is required if compare is specified.
(请注意,在这种情况下,您必须指定起始位置,如我链接的规范中所述: 如果指定了compare,则需要start参数。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…