Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to make IndexOf VB.NET display word count rather than character count

Posted on 2016-09-28
2
Medium Priority
?
50 Views
Last Modified: 2016-11-09
I have a basic piece of code.

    Sub Main()
        Dim Test As String = "test example"

        Console.WriteLine(Test.IndexOf("example"))
        Console.ReadLine()
    End Sub


The output would be "5" as the position of the start of the specified string is 5. I would still like to use indexof but how can i make it find the word location of the specified string such as it would output "2" as the word location is the 2nd word.
0
Comment
Question by:luke baker
[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 Comments
 
LVL 36

Accepted Solution

by:
Kimputer earned 2000 total points
ID: 41819814
Here's some code to work with. Please remember how to handle "errors" (text not found) yourself:

    Sub Main()
        Dim Test As String = "test example"
        Dim test_arr As String()
        test_arr = Split(Test, " ")


        Console.WriteLine("Index : " & Test.IndexOf("example"))
        Console.WriteLine("Word : " & test_arr.ToList().IndexOf("example") + 1)
        Console.ReadLine()
    End Sub

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

604 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