Solved

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

Posted on 2016-09-28
2
15 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
2 Comments
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

11 Experts available now in Live!

Get 1:1 Help Now