Solved

Instr in vb.net

Posted on 2009-05-05
4
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This is an explanation of a simple data model to help parse a JSON feed
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

751 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