Solved

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

Posted on 2016-09-28
2
23 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - Windows UserName index and length error 4 30
VB.NET (2008) - Refactoring Question 2 21
VB: Convert 2 dates to specific format 24 48
No Data for DropDown List 2 25
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 …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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