1
votes

I have a String like this:

"5/1/2017 7:11:15 PM | String is very long - part 1 - part 999 - 2017-04-28.dots, Replace Existing"

This is the sub string I want to find the position in main string:

"String is very long - part 1 - part 999 - 2017-04-28.dots"

I tried to find it using InStr Function like this:

MsgBox CStr(InStr("5/1/2017 7:11:15 PM | String is very long - part 1 - part 999 - 2017-04-28.dots, Replace Existing", "String is very long - part 1 - part 999 - 2017-04-28.dots", 1, 1))

The result I expected is 23.

Instead of the result, it throws the following Error:

Type mismatch: '[string: "5/1/2017 7:11:15 PM"]' (Code: 800A000D)

As this error depicts, can't I use InStr Function to deal with Strings those have spaces?

Thanks in Advance.

1

1 Answers

2
votes

See: https://www.w3schools.com/asp/func_instr.asp

You are giving InStr 4 parameters, which means it is expecting the first to be an integer indicating where in the string to start the search. So, since it is expecting an integer, and you're giving it a string, it throws the Type Mismatch.

Just move one of the 1s to be the first argument.