Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8722319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:23:12+00:00 2026-06-13T07:23:12+00:00

I am writing a program in Visual Basic 2010 that lists how many times

  • 0

I am writing a program in Visual Basic 2010 that lists how many times a word of each length occurs in a user-inputted string. Although most of the program is working, I have one problem:

When looping through all of the characters in the string, the program checks whether there is a next character (such that the program does not attempt to loop through characters that do not exist). For example, I use the condition:

If letter = Microsoft.VisualBasic.Right(input, 1) Then

Where letter is the character, input is the string, and Microsoft.VisualBasic.Right(input, 1) extracts the rightmost character from the string. Thus, if letter is the rightmost character, the program will cease to loop through the string.

This is where the problems comes in. Let us say the string is This sentence has five words. The rightmost character is an s, but an s is also the fourth and sixth character. That means that the first and second s will break the loop just as the others will.

My questions is whether there is a way to ensure that only the last s, or whatever character is the last one in the string can break the loop.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:23:14+00:00Added an answer on June 13, 2026 at 7:23 am

    There are a few methods you can use for this, one as Neolisk shows; here are a couple of others:

    Dim breakChar As Char = "s"
    Dim str As String = "This sentence has five words"
    
    str = str.Replace(".", " ")
    str = str.Replace(",", " ")
    str = str.Replace(vbTab, " ")
    ' other chars to replace
    
    Dim words() As String = str.ToLower.Split(New Char() {" "}, StringSplitOptions.RemoveEmptyEntries)
    For Each word In words
        If word.StartsWith(breakChar) Then Exit For
        Console.WriteLine("M1 Word: ""{0}""  Length: {1:N0}", word, word.Length)
    Next
    

    If you need to loop though chars for whatever reason, you can use something like this:

    Dim breakChar As Char = "s"
    Dim str As String = "This sentence has five words"
    
    str = str.Replace(".", " ")
    str = str.Replace(",", " ")
    str = str.Replace(vbTab, " ")
    ' other chars to replace
    
    'method 2
    Dim word As New StringBuilder
    Dim words As New List(Of String)
    
    For Each c As Char In str.ToLower.Trim
    
        If c = " "c Then
            If word.Length > 0 'support multiple white-spaces (double-space etc.)
                Console.WriteLine("M2 Word: ""{0}""  Length: {1:N0}", word.ToString, word.ToString.Length)
                words.Add(word.ToString)
                word.Clear()
            End If
        Else
            If word.Length = 0 And c = breakChar Then Exit For
            word.Append(c)
        End If
    Next
    
    If word.Length > 0 Then
        words.Add(word.ToString)
        Console.WriteLine("M2 Word: ""{0}""  Length: {1:N0}", word.ToString, word.ToString.Length)
    End If
    

    I wrote these specifically to break on the first letter in a word as you ask, adjust as needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a C++.NET 4.0 program that involves a form in Visual Studio 2010.
I am writing this program for visual basic that will determine a bill based
I am writing a program in Visual C# 2010 that has several icons on
I'm writing a program in Visual Basic 2010. It's a HMI (Human-Machine Interface) and
I'm writing a program for my visual basic class that computes the prices of
I'm writing an MPI program (Visual Studio 2k8 + MSMPI) that uses Boost::thread to
I am writing a small program in Visual Studio 11 (beta) that a console
I'm writing a program in c++/cli visual studio 2010 and I don't know how
I'm pretty new to C# and Visual Studio. I'm writing a small program that
I'm writing a program that uses the textbox in visual C# to read a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.