Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 407
  • Last Modified:

Instr in vb.net

I have a line :

I went to town
For shopping
This is one line
which is debugged as   "I went to town For shopping"

I want to find in line 'For ' word..How do I achieve this
0
RIAS
Asked:
RIAS
  • 2
2 Solutions
 
openshacCommented:
I am assuming that it is just a line break being used in the original string

        Dim myString As String
        myString = "I went to town\nFor shopping\nThis is one line"
 
        Dim start As Integer
        Dim firstLine As String
 
        start = InStr(myString, "\n")
        If (start > 0) Then
            firstLine = Mid(myString, start + 1)
        End If

Open in new window

0
 
RIASAuthor Commented:
Hi,
How to find a word after a particular index?
0
 
openshacCommented:
Sorry I though you were looking for the word after the line break, if you are looking for a specific word then try this:

        Dim myString As String
        myString = "I went to town\nFor shopping\nThis is one line"
 
        Dim start As Integer
        Dim firstLine As String
        Dim myWord As String
 
        myWord = "For"
        start = InStr(myString, myWord)
        If (start > 0) Then
            firstLine = Mid(myString, start + 1)
        End If

Open in new window

0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now