Solved

Instr in vb.net

Posted on 2009-05-05
4
397 Views
Last Modified: 2012-05-06
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
Comment
Question by:RIAS
  • 2
4 Comments
 
LVL 8

Assisted Solution

by:Haris V
Haris V earned 100 total points
ID: 24302985
0
 
LVL 6

Expert Comment

by:openshac
ID: 24303030
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
 

Author Comment

by:RIAS
ID: 24303141
Hi,
How to find a word after a particular index?
0
 
LVL 6

Accepted Solution

by:
openshac earned 150 total points
ID: 24303194
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
A short article about problems I had with the new location API and permissions in Marshmallow

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question