Examveda

What output will be returned if the following Visual Basic code is executed?

strVisualBasic = "Example, VB.Net"
intCharIndex = strVisualBasic.IndexOf("VB")

A. 8

B. 9

C. False

D. True

Answer: Option B

Solution (By Examveda Team)

The IndexOf function in Visual Basic is used to find the first occurrence of a specific string within another string.
In this code, strVisualBasic is assigned the string "Example, VB.Net".
The line intCharIndex = strVisualBasic.IndexOf("VB") attempts to find the starting position of the substring "VB" within strVisualBasic.
The IndexOf function returns the index (position) of the first character of the found substring. The index starts at 0.
In the string "Example, VB.Net", "VB" starts at the 9th position (remember counting starts at 0).
'E' is at index 0, 'x' is at index 1, 'a' is at index 2, 'm' is at index 3, 'p' is at index 4, 'l' is at index 5, 'e' is at index 6, ',' is at index 7, ' ' is at index 8, 'V' is at index 9.
Therefore, intCharIndex will be assigned the value 9.
So the correct answer is Option B: 9

This Question Belongs to Computer Science >> Visual Basic

Join The Discussion

Related Questions on Visual Basic