What output will be returned if the following Visual Basic code is executed?
strVisualBasic = "Example, VB.Net"
intCharIndex = strVisualBasic.IndexOf("VB")
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
Related Questions on Visual Basic
Which of the following extension is used to represent the project file in Visual Basic?
A. .vbp
B. .vb
C. .cls
D. .vvb
Which of the following applications can be developed using Visual Basic tool?
A. Graphical User Interface
B. Real-time
C. Character User Interface
D. All of the mentioned
In visual basic language what are the rules of a programming language called?
A. Grammar
B. Order
C. Syntax
D. Rules

Join The Discussion