What output will be returned if the following Visual Basic code is executed? strCityState = “Nashville, TN” intCharIndex = strCityState.IndexOf(“TN”)

TRUE
FALSE
11
12

The correct answer is C. 11.

The IndexOf method returns the index of the first occurrence of a specified string within a string. In this case, the string “TN” is found at index 11, so the IndexOf method returns 11.

Option A is incorrect because the IndexOf method returns an integer, not a Boolean value.

Option B is incorrect because the IndexOf method does not return False if the specified string is not found.

Option D is incorrect because the IndexOf method returns the index of the first occurrence of the specified string, not the last occurrence.

Exit mobile version