ADVERTISEMENT
ADVERTISEMENT

VB.Net program to demonstrate the InStr() function

Here, we are going to demonstrate the InStr() function in VB.Net.
Submitted by Nidhi, on December 04, 2020

The InStr() function is used to search the substring in the specified string.

Syntax:

InStr(Str, SubStr)

Parameters:

  • Str: Specified string that may contain given substring.
  • SubStr: Specified sub-string to be searched.

Return Value:

The InStr() function will return an integer value, if a substring is found then it will return the starting index of the substring within the string.

Program/Source Code:

The source code to demonstrate the InStr() function is given below. The given program is compiled and executed successfully.

'VB.Net program to demonstrate the InStr() function.

Module Module1

    Sub Main()
        Dim str As String = "I love india"
        Dim substr As String = "love"

        Dim ret As Integer = 0

        ret = InStr(str, substr)

        If ret = 0 Then
            Console.WriteLine("Substring {0} is not found", substr)
        Else
            Console.WriteLine("Substring {0} is found at index {1}", substr, ret)
        End If

    End Sub
    
End Module

Output:

Substring love is found at index 3
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a Main() method. In the Main() method, we created three variables str, substr, ret that are initialized with "I love india", "love", and 0 respectively.

ret = InStr(str, substr)

In the above code, we used the InStr() function that will return an integer value, if a substring is found then it will return the starting index of the substring within the string.

VB.Net Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.