Solved

Instr in vb.net

Posted on 2009-05-05
4
395 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article will show, step by step, how to integrate R code into a R Sweave document
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now